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

我有能力这样做:

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

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


当前回答

我通过使用——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分支:

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

我知道这不是问题的全部范围,但如果你发现只需要过滤特定作者提交的文件,你总是可以管道到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'

编码快乐!:)

警告!

注意,这些命令显示了分支指向的提交数据,因此提交作者可能与分支作者不同。 Git不存储分支创建者,只存储提交的一个。

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

DarVar补充道:

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

附注:我们使用AWK来漂亮地打印作者和远程分支。