Find out a Git branch creator

前端 未结 11 1345
陌清茗
陌清茗 2020-11-28 17:57

I want to find out who created a branch.

I am sort of able to do so with:

git branch -a | xargs -L 1 bash -c \'echo \"$1 `git log --pretty=format:\"%         


        
相关标签:
11条回答
  • 2020-11-28 18:20

    As far as I know, you may see if you are the creator of a branch only. This is indicated by the first row in .git/ref/heads/<branch>. If it ends with "Created from HEAD" you are the creator.

    0 讨论(0)
  • 2020-11-28 18:25

    List remote Git branches by author sorted by committer date:

    git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' --sort=committerdate
    
    0 讨论(0)
  • 2020-11-28 18:28

    Adding to DarVar's answer:

    git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' | sort -k5n -k2M -k3n -k4n | awk '{print $7 $8}'
    

    P.S.: We used AWK to pretty print the author and the remote branch.

    0 讨论(0)
  • 2020-11-28 18:31

    Assuming:

    1. branch was made from master
    2. hasn't been merged to master yet

     git log --format="%ae %an" master..<HERE_COMES_THE_BRANCH_NAME> | tail -1
    
    0 讨论(0)
  • 2020-11-28 18:34

    A branch is nothing but a commit pointer. As such, it doesn't track metadata like "who created me." See for yourself. Try cat .git/refs/heads/<branch> in your repository.

    That written, if you're really into tracking this information in your repository, check out branch descriptions. They allow you to attach arbitrary metadata to branches, locally at least.

    Also DarVar's answer below is a very clever way to get at this information.

    0 讨论(0)
  • 2020-11-28 18:34

    We can find out based upon authorname

    git for-each-ref --format='%(authorname) %09 %(if)%(HEAD)%(then)*%(else)%(refname:short)%(end) %09 %(creatordate)' refs/remotes/ --sort=authorname DESC
    
    0 讨论(0)
提交回复
热议问题