How to get commit where merged branch forked from

微笑、不失礼 提交于 2019-11-29 10:14:24
Willem D'Haeseleer

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 !

As you noticed, git merge-base will not help you. The reason for this is that feature is part of master’s history and it could be fast-forwarded to master.

If this is your specific setup though, that you have merged feature into master, and the feature branch still points to the commit before the merge, then you can just get all the commits that are included in master but not included in feature and take the last one; the merge base you are looking for is its parent. You can do that by specifying the range feature..master:

git show $(git rev-list feature..master | tail -1)~1

This will show you the merge base commit “1” in your graph.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!