Find out a Git branch creator

前端 未结 11 1346
陌清茗
陌清茗 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:36
    git for-each-ref --format='%(authorname) %09 -%(refname)' | sort
    
    0 讨论(0)
  • 2020-11-28 18:40

    You can find out who created a branch in your local repository by

    git reflog --format=full
    

    Example output:

    commit e1dd940
    Reflog: HEAD@{0} (a <a@none>)
    Reflog message: checkout: moving from master to b2
    Author: b <b.none>
    Commit: b <b.none>
    (...)
    

    But this is probably useless as typically on your local repository only you create branches.

    The information is stored at ./.git/logs/refs/heads/branch. Example content:

    0000000000000000000000000000000000000000 e1dd9409c4ba60c28ad9e7e8a4b4c5ed783ba69b a <a@none> 1438788420 +0200   branch: Created from HEAD
    

    The last commit in this example was from user "b" while the branch "b2" was created by user "a". If you change your username you can verify that git reflog takes the information from the log and does not use the local user.

    I don't know about any possibility to transmit that local log information to a central repository.

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

    I tweaked the previous answers by using the --sort flag and added some color/formatting:

    git for-each-ref --format='%(color:cyan)%(authordate:format:%m/%d/%Y %I:%M %p)    %(align:25,left)%(color:yellow)%(authorname)%(end) %(color:reset)%(refname:strip=3)' --sort=authordate refs/remotes
    
    0 讨论(0)
  • 2020-11-28 18:41

    for those looking for a DESC ... this seems to work --sort=-

    ty for the formatting, new to this ...my eyes are loosing some of it's bloodshot

    git for-each-ref --format='%(color:cyan)%(authordate:format:%m/%d/%Y %I:%M %p)    %(align:25,left)%(color:yellow)%(authorname)%(end) %(color:reset)%(refname:strip=3)' --sort=-authordate refs/remotes
    

    further ref: https://stackoverflow.com/a/5188364/10643471

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

    I know this is not entirely the scope of the question, but if you find the need to filter only commits by a specific author, you can always pipe to grep :)

    # lists all commits in chronological order that
    # belong to the github account with
    # username `MY_GITHUB_USERNAME` (obviously you
    # would want to replace that with your github username,
    # or the username you are trying to filter by)
    
    
    git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' | sort -committerdate | grep 'MY_GITHUB_USERNAME'
    

    happy coding! :)

    0 讨论(0)
提交回复
热议问题