我想找出是谁创建了分支。
我有能力这样做:
git branch -a | xargs -L 1 bash -c 'echo "$1 `git log --pretty=format:"%H %an" $1^..$1`"' _
但是,这将返回每个分支的最后一个提交者,而不一定是创建该分支的人。
我想找出是谁创建了分支。
我有能力这样做:
git branch -a | xargs -L 1 bash -c 'echo "$1 `git log --pretty=format:"%H %an" $1^..$1`"' _
但是,这将返回每个分支的最后一个提交者,而不一定是创建该分支的人。
当前回答
按提交日期排序的作者列出远程Git分支:
git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' --sort=committerdate
其他回答
我们可以根据作者名找到答案
git for-each-ref --format='%(authorname) %09 %(if)%(HEAD)%(then)*%(else)%(refname:short)%(end) %09 %(creatordate)' refs/remotes/ --sort=authorname DESC
我通过使用——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
您可以通过以下方法找到是谁在本地存储库中创建了分支
git reflog --format=full
示例输出:
commit e1dd940
Reflog: HEAD@{0} (a <a@none>)
Reflog message: checkout: moving from master to b2
Author: b <b.none>
Commit: b <b.none>
(...)
但这可能是无用的,因为通常只有在本地存储库中才创建分支。
信息存储在。/.git/logs/refs/heads/branch。 内容示例:
0000000000000000000000000000000000000000 e1dd9409c4ba60c28ad9e7e8a4b4c5ed783ba69b a <a@none> 1438788420 +0200 branch: Created from HEAD
本例中的最后一次提交来自用户“b”,而分支“b2”是由用户“a”创建的。如果你改变了你的用户名,你可以验证git reflog从日志中获取信息,而不是使用本地用户。
我不知道是否有可能将本地日志信息传输到中央存储库。
我知道这不是问题的全部范围,但如果你发现只需要过滤特定作者提交的文件,你总是可以管道到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'
编码快乐!:)
DarVar补充道:
git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' | sort -k5n -k2M -k3n -k4n | awk '{print $7 $8}'
附注:我们使用AWK来漂亮地打印作者和远程分支。