I am running this on a feature branch:
git fetch origin
git merge-base --fork-point origin/dev; echo $?
the git merge-base
command is exiting with 1, but logging zero stdout/stderr.
I can't figure out why the merge-base
command wouldn't yield a ref, anyone know why that might happen?
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.
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. the merge base between A and B is 1.
The result of git merge-base --octopus A B C is 2, because 2 is the best common ancestor of all commits. When the history involves criss-cross merges, there can be more than one best common ancestor for two commits. For example, with this topology:
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. Compute the best common ancestors of all supplied commits, in preparation for an n-way merge.
The caveats mentioned by torek are part of the git merge-base
discussion on fork-point mode.
o---B2 / ---o---o---B1--o---o---o---B (origin/master) \ \ B0 D0'--D1'--D' (topic - updated) \ D0---D1---D (topic - old)
A caveat is that older reflog entries in your repository may be expired by
git gc
.
IfB0
no longer appears in the reflog of the remote-tracking branchorigin/master
, the--fork-point
mode obviously cannot find it and fails, avoiding to give a random and useless result (such as the parent of B0, like the same command without the--fork-point
option gives).Also, the remote-tracking branch you use the
--fork-point
mode with must be the one your topic forked from its tip.
If you forked from an older commit than the tip, this mode would not find the fork point (imagine in the above sample historyB0
did not exist,origin/master
started atB1
, moved toB2
and thenB
, and you forked yourtopic
atorigin/master^
whenorigin/master
wasB1
; the shape of the history would be the same as above, withoutB0
, and the parent ofB1
is whatgit merge-base origin/master topic
correctly finds, but the--fork-point
mode will not, because it is not one of the commits that used to be at the tip oforigin/master
).
You can see additional scenario where git merge-base --fork-point
doesn't work in this thread.
This patch series illustrate the current documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With