我想找出是谁创建了分支。

我有能力这样做:

git branch -a | xargs -L 1 bash -c 'echo "$1 `git log --pretty=format:"%H %an" $1^..$1`"' _

但是,这将返回每个分支的最后一个提交者,而不一定是创建该分支的人。


当前回答

您可以通过以下方法找到是谁在本地存储库中创建了分支

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从日志中获取信息,而不是使用本地用户。

我不知道是否有可能将本地日志信息传输到中央存储库。

其他回答

git for-each-ref --format='%(authorname) %09 -%(refname)' | sort

据我所知,您可以看到您是否只是一个分支的创建者。这由.git/ref/heads/<branch>中的第一行表示。如果它以“Created from HEAD”结尾,你就是创造者。

您可以通过以下方法找到是谁在本地存储库中创建了分支

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从日志中获取信息,而不是使用本地用户。

我不知道是否有可能将本地日志信息传输到中央存储库。

对于那些正在寻找DESC的人…这似乎是可行的——sort=-

Ty的格式,这是新的…我的眼睛有些血丝脱落了

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

进一步参考:https://stackoverflow.com/a/5188364/10643471

按提交日期排序的作者列出远程Git分支:

git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' --sort=committerdate