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-svn refuses to create branch on svn repository error: “not in the same repository”
  • How do you stop tracking a remote branch in Git?
  • Why don't Git refs have a file extension
  • Pushing to a remote branch (failed to update ref)
  • cannot checkout remote git branch
  • Git-svn: managing multiple remote tracking branchs
  • 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:

    • How to get a branch into a forked repo from the original repo in github
    • git how to find commit hash where branch originated from
    • How to get information where branch starts?

  • Git: undoing an unknown mistake
  • something like same “tag” for multiple commits
  • Github - How to return the whole project to a certain commit in Webstorm
  • I cloned a repository into my project. Should I commit that repo in my project repo?
  • heroku fatal error
  • How to pull from the remote using dulwich?
  • 2 Solutions collect form web for “How to get commit where merged branch forked from”

    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.

    Git Baby is a git and github fan, let's start git clone.