How to find the nearest parent of a Git branch?

后端 未结 21 1665
野性不改
野性不改 2020-11-22 00:54

Let\'s say I have the following local repository with a commit tree like this:

master --> a
            \\
             \\
      develop c --> d
               


        
21条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-11-22 00:59

    This did not work for me when I had done something like develop > release-v1.0.0 > feature-foo, it would go all the way back to develop, note there was a rebase involved, not sure if that is compounding my issue...

    The following did give the correct commit hash for me

    git log --decorate \
      | grep 'commit' \
      | grep 'origin/' \
      | head -n 2 \
      | tail -n 1 \
      | awk '{ print $2 }' \
      | tr -d "\n"
    

提交回复
热议问题