Finding a branch point with Git?

前端 未结 22 1321
小鲜肉
小鲜肉 2020-11-22 10:11

I have a repository with branches master and A and lots of merge activity between the two. How can I find the commit in my repository when branch A was created based on mast

22条回答
  •  伪装坚强ぢ
    2020-11-22 10:42

    Here's an improved version of my previous answer previous answer. It relies on the commit messages from merges to find where the branch was first created.

    It works on all the repositories mentioned here, and I've even addressed some tricky ones that spawned on the mailing list. I also wrote tests for this.

    find_merge ()
    {
        local selection extra
        test "$2" && extra=" into $2"
        git rev-list --min-parents=2 --grep="Merge branch '$1'$extra" --topo-order ${3:---all} | tail -1
    }
    
    branch_point ()
    {
        local first_merge second_merge merge
        first_merge=$(find_merge $1 "" "$1 $2")
        second_merge=$(find_merge $2 $1 $first_merge)
        merge=${second_merge:-$first_merge}
    
        if [ "$merge" ]; then
            git merge-base $merge^1 $merge^2
        else
            git merge-base $1 $2
        fi
    }
    

提交回复
热议问题