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] <commit> <commit>...
10
12 git merge-base finds best common ancestor(s) between two commits to use
13 in a three-way merge. One common ancestor is better than another common
14 ancestor if the latter is an ancestor of the former. A common ancestor
15 that does not have any better common ancestor is a best common
16 ancestor, i.e. a merge base. Note that there can be more than one merge
17 base for a pair of commits.
18
19 Among the two commits to compute the merge base from, one is specified
20 by the first commit argument on the command line; the other commit is a
21 (possibly hypothetical) commit that is a merge across all the remaining
22 commits on the command line. As the most common special case,
23 specifying only two commits on the command line means computing the
24 merge base between the given two commits.
25
26 As a consequence, the merge base is not necessarily contained in each
27 of the commit arguments if more than two commits are specified. This is
28 different from git-show-branch(1) when used with the --merge-base
29 option.
30
32 -a, --all
33 Output all merge bases for the commits, instead of just one.
34
36 Given two commits A and B, git merge-base A B will output a commit
37 which is reachable from both A and B through the parent relationship.
38
39 For example, with this topology:
40
41 o---o---o---B
42 /
43 ---o---1---o---o---o---A
44
45 the merge base between A and B is 1.
46
47 Given three commits A, B and C, git merge-base A B C will compute the
48 merge base between A and a hypothetical commit M, which is a merge
49 between B and C. For example, with this topology:
50
51 o---o---o---o---C
52 /
53 / o---o---o---B
54 / /
55 ---2---1---o---o---o---A
56
57 the result of git merge-base A B C is 1. This is because the equivalent
58 topology with a merge commit M between B and C is:
59
60 o---o---o---o---o
61 / \
62 / o---o---o---o---M
63 / /
64 ---2---1---o---o---o---A
65
66 and the result of git merge-base A M is 1. Commit 2 is also a common
67 ancestor between A and M, but 1 is a better common ancestor, because 2
68 is an ancestor of 1. Hence, 2 is not a merge base.
69
70 When the history involves criss-cross merges, there can be more than
71 one best common ancestor for two commits. For example, with this
72 topology:
73
74 ---1---o---A
75 \ /
76 X
77 / \
78 ---2---o---o---B
79
80 both 1 and 2 are merge-bases of A and B. Neither one is better than the
81 other (both are best merge bases). When the --all option is not given,
82 it is unspecified which best one is output.
83
85 Written by Linus Torvalds <torvalds@osdl.org[1]>
86
88 Documentation by David Greaves, Junio C Hamano and the git-list
89 <git@vger.kernel.org[2]>.
90
92 Part of the git(1) suite
93
95 1. torvalds@osdl.org
96 mailto:torvalds@osdl.org
97
98 2. git@vger.kernel.org
99 mailto:git@vger.kernel.org
100
101
102
103Git 1.7.1 08/16/2017 GIT-MERGE-BASE(1)