How to find the nearest parent of a Git branch?

后端 未结 21 1644
野性不改
野性不改 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 01:09

    I have a solution to your overall problem (determine if feature is descended from the tip of develop), but it doesn't work using the method you outlined.

    You can use git branch --contains to list all the branches descended from the tip of develop, then use grep to make sure feature is among them.

    git branch --contains develop | grep "^ *feature$"
    

    If it is among them, it will print " feature" to standard output and have a return code of 0. Otherwise, it will print nothing and have a return code of 1.

提交回复
热议问题