Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
198 views
in Technique[技术] by (71.8m points)

git-merge-base returns only one commit

When I merge between branches, git does a recursive merge with conflicts, putting in <<<<<<< Temporary merge branch x blocks.

I abort the merge, and then do git merge-base <source-commit> <target-commit>, but it returns only one SHA1.

Is it possible to find out what the multiple base commits are?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You want the --all option to git-merge-base. From the documentation:

-a, --all
    Output all merge bases for the commits, instead of just one.

This will show all the merge bases that will be used to create a temporary tree as a recursive merge base.

For example, consider some branches 'A' and 'B' that were criss-cross merged:

       3a4f5a6 -- 973b703 -- a34e5a1 (branch A)
      /         /
7c7bf85         X
              / 
       8f35f30 -- 3fd4180 -- 723181f (branch B)

It's clear that branches A and B have two common ancestors that were involved in a criss-cross merge: 3a3f5a6 and 8f35f30. git-merge-base will choose one of the common ancestors as a merge base, but using the --all flag will include both:

% git-merge-base A B
3a3f5a6ec1c968d1d2d5d20dee0d161a4351f279
% git-merge-base --all A B
3a3f5a6ec1c968d1d2d5d20dee0d161a4351f279
8f35f30bfe09513f96cf8aa4df0834ae34e93bae

In this situation, as you note, git-merge-recursive would merge the two merge base to create a virtual commit that will be used as the actual common ancestor for the three-way merge algorithm.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...