且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

git:我如何找到两个分支的共同祖先......已经合并了

更新时间:2023-11-23 15:43:22

If you do

git merge-base C I

you get the commit A you want. What are C and I? They are the parent commits of your merge commit D.

Hoy do you get them?

git log --pretty=%P -n 1 D 

gives you two strings. This two strings are the commit C and I you need.

If you want to do it all together you can write

git merge-base $(git log --pretty=%P -n 1 MERGE_COMMIT)

where you have to replace MERGE_COMMIT with the hash of your merge commit D

Edit: As @poke stated it is simpler with

git merge-base MERGE_COMMIT^ MERGE_COMMIT^2