How to find the nearest parent of a Git branch?

后端 未结 21 1646
野性不改
野性不改 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:22

    Here's my Powershell Version:

    function Get-GHAParentBranch {
        [CmdletBinding()]
        param(
            $Name = (git branch --show-current)
        )
        git show-branch | 
          Select-String '^[^\[]*\*' | 
          Select-String -NotMatch -Pattern "\[$([Regex]::Escape($Name)).*?\]" |
          Select-Object -First 1 |
          Foreach-Object {$PSItem -replace '^.+?\[(.+)\].+$','$1'}
    }
    

提交回复
热议问题