找出一个 Git 分支创建者

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12055198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:25:46  来源:igfitidea点击:

Find out a Git branch creator

gitgit-branch

提问by Ofir Farchy

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 " `git log --pretty=format:"%H %an" ^..`"' _

However, this returns the last committer per branch, not necessarily the person who created the branch.

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

采纳答案by Christopher

A branch is nothing but a commit pointer. As such, it doesn't track metadata like "who created me." See for yourself. Try cat .git/refs/heads/<branch>in your repository.

一个分支只不过是一个提交指针。因此,它不会跟踪“谁创建了我”之类的元数据。你自己看。cat .git/refs/heads/<branch>在您的存储库中尝试。

That written, if you're really into tracking this information in your repository, check out branch descriptions.They allow you to attach arbitrary metadata to branches, locally at least.

写到这里,如果您真的想在存储库中跟踪此信息,请查看分支描述。它们允许您至少在本地将任意元数据附加到分支。

Also DarVar's answer belowis a very clever way to get at this information.

低于DarVar的回答是一个非常聪明的方式来获得这方面的资料。

回答by DarVar

List remote Git branches by author sorted by committer date:

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

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

回答by Mike

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

我通过使用--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

回答by suryakrupa

Adding to DarVar's answer:

添加到DarVar 的答案

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

P.S.: We used AWK to pretty print the author and the remote branch.

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

回答by KhaledMohamedP

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

回答by Gustave

You can find out who created a branch in your localrepository 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:

信息存储在 ./.git/logs/refs/heads/ branch。示例内容:

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.

此示例中的最后一次提交来自用户“b”,而分支“b2”由用户“a”创建。如果您更改您的用户名,您可以验证 git reflog 从日志中获取信息并且不使用本地用户。

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

我不知道将本地日志信息传输到中央存储库的任何可能性。

回答by tech2504

We can find out based upon authorname

我们可以根据作者姓名找出

git for-each-ref --format='%(authorname) %09 %(if)%(HEAD)%(then)*%(else)%(refname:short)%(end) %09 %(creatordate)' refs/remotes/ --sort=authorname DESC

回答by Trident D'Gao

Assuming:

假设:

  1. branch was made from master
  2. hasn't been merged to masteryet
  1. 分支是由 master
  2. 尚未合并master尚未


 git log --format="%ae %an" master..<HERE_COMES_THE_BRANCH_NAME> | tail -1

回答by avocadojesus

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 :)

我知道这不完全是问题的范围,但是如果您发现需要仅过滤特定作者的提交,您可以随时通过管道传递给 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! :)

快乐编码!:)

回答by rob bee

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

对于那些寻找 DESC 的人......这似乎有效 --sort=-

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

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

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

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