Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

git - How to get commit where merged branch forked from

o---1---o---o---o---o     master
              /
      o---o---2           feature

Is it possible to get commit 1 without using reflog ? Using git 2.4.2

I tried:

git merge-base master feature
git merge-base feature master
returns: commit 2 
git merge-base --fork-point master feature
git merge-base --fork-point feature master
returns nothing ( exit code 1 )

Not duplicates:

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Found my answer as a subset from this question: ( backporting was in fact also my usecase ! ) https://stackoverflow.com/a/16718891/867294

[alias]
    oldest-ancestor = !bash -c 'diff -u <(git rev-list --first-parent "${1:-master}") <(git rev-list --first-parent "${2:-HEAD}") | sed -ne "s/^ //p" | head -1' -

I am somewhat baffled that this is not part of git as default. You would at least expect that this would be the behavior of the --fork-point option for merge-base. If anyone knows a better/default alternative. Please put it in the comments or as a separate answer !


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...