table of contents
other versions
- wheezy 1:1.7.10.4-1+wheezy3
- wheezy-backports 1:1.9.1-1~bpo70+2
- jessie 1:2.1.4-2.1+deb8u2
- jessie-backports 1:2.11.0-3~bpo8+1
- testing 1:2.11.0-3
- unstable 1:2.11.0-4
- experimental 1:2.13.1+next.20170610-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.Compute 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.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) suite04/08/2014 | Git 1.9.1 |