1GIT-MERGE-BASE(1) Git Manual GIT-MERGE-BASE(1)
2
3
4
6 git-merge-base - Find as good common ancestors as possible for a merge
7
9 git merge-base [-a|--all] [--octopus] <commit> <commit>...
10 git merge-base --independent <commit>...
11
12
14 git merge-base finds best common ancestor(s) between two commits to use
15 in a three-way merge. One common ancestor is better than another common
16 ancestor if the latter is an ancestor of the former. A common ancestor
17 that does not have any better common ancestor is a best common
18 ancestor, i.e. a merge base. Note that there can be more than one merge
19 base for a pair of commits.
20
21 Unless --octopus is given, among the two commits to compute the merge
22 base from, one is specified by the first commit argument on the command
23 line; the other commit is a (possibly hypothetical) commit that is a
24 merge across all the remaining commits on the command line. As the most
25 common special case, specifying only two commits on the command line
26 means computing the merge base between the given two commits.
27
28 As a consequence, the merge base is not necessarily contained in each
29 of the commit arguments if more than two commits are specified. This is
30 different from git-show-branch(1) when used with the --merge-base
31 option.
32
34 -a, --all
35 Output all merge bases for the commits, instead of just one.
36
37 --octopus
38 Compute the best common ancestors of all supplied commits, in
39 preparation for an n-way merge. This mimics the behavior of git
40 show-branch --merge-base.
41
42 --independent
43 Instead of printing merge bases, print a minimal subset of the
44 supplied commits with the same ancestors. In other words, among the
45 commits given, list those which cannot be reached from any other.
46 This mimics the behavior of git show-branch --independent.
47
49 Given two commits A and B, git merge-base A B will output a commit
50 which is reachable from both A and B through the parent relationship.
51
52 For example, with this topology:
53
54 o---o---o---B
55 /
56 ---o---1---o---o---o---A
57
58 the merge base between A and B is 1.
59
60 Given three commits A, B and C, git merge-base A B C will compute the
61 merge base between A and a hypothetical commit M, which is a merge
62 between B and C. For example, with this topology:
63
64 o---o---o---o---C
65 /
66 / o---o---o---B
67 / /
68 ---2---1---o---o---o---A
69
70 the result of git merge-base A B C is 1. This is because the equivalent
71 topology with a merge commit M between B and C is:
72
73 o---o---o---o---o
74 / \
75 / o---o---o---o---M
76 / /
77 ---2---1---o---o---o---A
78
79 and the result of git merge-base A M is 1. Commit 2 is also a common
80 ancestor between A and M, but 1 is a better common ancestor, because 2
81 is an ancestor of 1. Hence, 2 is not a merge base.
82
83 When the history involves criss-cross merges, there can be more than
84 one best common ancestor for two commits. For example, with this
85 topology:
86
87 ---1---o---A
88 \ /
89 X
90 / \
91 ---2---o---o---B
92
93 both 1 and 2 are merge-bases of A and B. Neither one is better than the
94 other (both are best merge bases). When the --all option is not given,
95 it is unspecified which best one is output.
96
98 Written by Linus Torvalds <torvalds@osdl.org[1]>
99
101 Documentation by David Greaves, Junio C Hamano and the git-list
102 <git@vger.kernel.org[2]>.
103
105 git-rev-list(1), git-show-branch(1), git-merge(1)
106
108 Part of the git(1) suite
109
111 1. torvalds@osdl.org
112 mailto:torvalds@osdl.org
113
114 2. git@vger.kernel.org
115 mailto:git@vger.kernel.org
116
117
118
119Git 1.7.4.4 04/11/2011 GIT-MERGE-BASE(1)