Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git merge-base --fork-point <ref> is yielding nothing

Tags:

git

git-merge

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?

like image 878
Alexander Mills Avatar asked Sep 25 '18 19:09

Alexander Mills


People also ask

How does Git merge-base find best common ancestor?

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.

What is the merge base between a and B in Git?

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.

What is the result of Git merge-base --octopus?

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:

Why is the merge base not in each commit?

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.


Video Answer


1 Answers

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.
If B0 no longer appears in the reflog of the remote-tracking branch origin/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 history B0 did not exist, origin/master started at B1, moved to B2 and then B, and you forked your topic at origin/master^ when origin/master was B1; the shape of the history would be the same as above, without B0, and the parent of B1 is what git 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 of origin/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.

like image 85
VonC Avatar answered Oct 05 '22 22:10

VonC