table of contents
other versions
- jessie 1:2.1.4-2.1+deb8u6
- jessie-backports 1:2.11.0-3~bpo8+1
- stretch 1:2.11.0-3+deb9u4
- testing 1:2.20.1-2
- stretch-backports 1:2.20.1-1~bpo9+1
- unstable 1:2.20.1-2
- experimental 1:2.21.0+next.20190320-1
GIT-MERGE-BASE(1) | Git Manual | GIT-MERGE-BASE(1) |
NAME¶
git-merge-base - Find as good common ancestors as possible for a mergeSYNOPSIS¶
git merge-base [-a|--all] <commit> <commit>... git merge-base [-a|--all] --octopus <commit>... git merge-base --is-ancestor <commit> <commit> git merge-base --independent <commit>... git merge-base --fork-point <ref> [<commit>]
DESCRIPTION¶
git merge-base finds best common ancestor(s) between two commits to use in a three-way merge. One common ancestor is better than another common ancestor if the latter is an ancestor of the former. A common ancestor that does not have any better common ancestor is a best common ancestor, i.e. a merge base. Note that there can be more than one merge base for a pair of commits.OPERATION MODES¶
As the most common special case, specifying only two commits on the command line means computing the merge base between the given two commits. More generally, among the two commits to compute the merge base from, one is specified by the first commit argument on the command line; the other commit is a (possibly hypothetical) commit that is a merge across all the remaining commits on the command line. As a consequence, the merge base is not necessarily contained in each of the commit arguments if more than two commits are specified. This is different from git-show-branch(1) when used with the --merge-base option. --octopusCompute the best common ancestors of all supplied
commits, in preparation for an n-way merge. This mimics the behavior of git
show-branch --merge-base.
--independent
Instead of printing merge bases, print a minimal subset
of the supplied commits with the same ancestors. In other words, among the
commits given, list those which cannot be reached from any other. This mimics
the behavior of git show-branch --independent.
--is-ancestor
Check if the first <commit> is an ancestor of the
second <commit>, and exit with status 0 if true, or with status 1 if
not. Errors are signaled by a non-zero status that is not 1.
--fork-point
Find the point at which a branch (or any history that
leads to <commit>) forked from another branch (or any reference)
<ref>. This does not just look for the common ancestor of the two
commits, but also takes into account the reflog of <ref> to see if the
history leading to <commit> forked from an earlier incarnation of the
branch <ref> (see discussion on this mode below).
OPTIONS¶
-a, --allOutput all merge bases for the commits, instead of just
one.
DISCUSSION¶
Given two commits A and B, git merge-base A B will output a commit which is reachable from both A and B through the parent relationship. For example, with this topology:o---o---o---B / ---o---1---o---o---o---A
o---o---o---o---C / / o---o---o---B / / ---2---1---o---o---o---A
o---o---o---o---o / \ / o---o---o---o---M / / ---2---1---o---o---o---A
---1---o---A \ / X / \ ---2---o---o---B
A=$(git rev-parse --verify A) if test "$A" = "$(git merge-base A B)" then ... A is an ancestor of B ... fi
if git merge-base --is-ancestor A B then ... A is an ancestor of B ... fi
DISCUSSION ON FORK-POINT MODE¶
After working on the topic branch created with git checkout -b topic origin/master, the history of remote-tracking branch origin/master may have been rewound and rebuilt, leading to a history of this shape:o---B1 / ---o---o---B2--o---o---o---B (origin/master) \ B3 \ Derived (topic)
$ fork_point=$(git merge-base --fork-point origin/master topic) $ git rebase --onto origin/master $fork_point topic
SEE ALSO¶
git-rev-list(1), git-show-branch(1), git-merge(1)GIT¶
Part of the git(1) suite05/28/2018 | Git 2.1.4 |