Ofi*_*chy 139 git git-branch
我想找出谁创建了一个分支.
我有点能够这样做:
git branch -a | xargs -L 1 bash -c 'echo "$1 `git log --pretty=format:"%H %an" $1^..$1`"' _
Run Code Online (Sandbox Code Playgroud)
但是,这会返回每个分支的最后一个提交者,而不一定是创建分支的人.
Dar*_*Var 266
列出远程Git分支按作者排序的committerdate:
git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' --sort=committerdate
Run Code Online (Sandbox Code Playgroud)
Mik*_*ike 42
我通过使用--sort标志并添加一些颜色/格式来调整上述答案.
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
Run Code Online (Sandbox Code Playgroud)
git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' | sort -k5n -k2M -k3n -k4n | awk '{print $7 $8}'
Run Code Online (Sandbox Code Playgroud)
PS我们使用awk来打印作者和远程分支
git for-each-ref --format='%(authorname) %09 -%(refname)' | sort
Run Code Online (Sandbox Code Playgroud)
您可以通过以下方式找出谁在您的本地存储库中创建了一个分支
git reflog --format=full
Run Code Online (Sandbox Code Playgroud)
示例输出:
commit e1dd940
Reflog: HEAD@{0} (a <a@none>)
Reflog message: checkout: moving from master to b2
Author: b <b.none>
Commit: b <b.none>
(...)
Run Code Online (Sandbox Code Playgroud)
但这可能是无用的,因为通常在您的本地存储库中只有您创建分支。
信息存储在 ./.git/logs/refs/heads/ branch。示例内容:
0000000000000000000000000000000000000000 e1dd9409c4ba60c28ad9e7e8a4b4c5ed783ba69b a <a@none> 1438788420 +0200 branch: Created from HEAD
Run Code Online (Sandbox Code Playgroud)
此示例中的最后一次提交来自用户“b”,而分支“b2”由用户“a”创建。如果您更改您的用户名,您可以验证 git reflog 从日志中获取信息并且不使用本地用户。
我不知道将本地日志信息传输到中央存储库的任何可能性。
假设:
mastermaster尚未合并到 git log --format="%ae %an" master..<HERE_COMES_THE_BRANCH_NAME> | tail -1
Run Code Online (Sandbox Code Playgroud)
我们可以根据作者姓名找出
git for-each-ref --format='%(authorname) %09 %(if)%(HEAD)%(then)*%(else)%(refname:short)%(end) %09 %(creatordate)' refs/remotes/ --sort=authorname DESC
Run Code Online (Sandbox Code Playgroud)