git 分支上的提交次数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10913892/
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
Number of commits on branch in git
提问by Andrey Ermakov
I'm writing a small script and want to know how many commits I made on a current branch since it was created.
我正在编写一个小脚本,想知道自创建以来我在当前分支上做了多少提交。
In this example I'd have 2 commits made on child
:
在这个例子中,我有 2 个提交child
:
git checkout master
git checkout -b child
...
git commit -a
...
git commit -a
So what I want is
所以我想要的是
commit_number = ...
echo $commit_number
Thank you for your help.
感谢您的帮助。
回答by Kissaki
Git can provide you with the number of commits without further shell scripting.
Git 可以为您提供提交次数,而无需进一步编写 shell 脚本。
git rev-list master.. --count
rev-list(listed in git help -a
) is used to work with revisions.
rev-list(在 中列出git help -a
)用于处理修订。
As master..
will list the commits from the base of master and the current branch up to the current branch, --count
will give you the count of them.
作为master..
将列出主的基础和当前分支到当前分支的提交,--count
会给你他们的计数。
If you would instead want to have the number of commits between the two revisions you would use master...
. To elaborate: between as in from master to the most recent common ancestor of master and the current branch (HEAD), and up to the current branch again. If you visualize the commit history as a tree you should be able to follow the two branches from the common ancestor. master..
on the other hand will just count one of the two branches.
如果您希望在两个修订版之间拥有提交次数,则可以使用master...
. 详细说明:在从 master 到 master 和当前分支(HEAD)的最新共同祖先之间,再到当前分支。如果您将提交历史可视化为一棵树,您应该能够跟踪来自共同祖先的两个分支。master..
另一方面,只会计算两个分支中的一个。
So whether you want to use master..
or master...
depends on whether you want to know how many commits you made in your branchsince you split it off (master..
), or the difference between the currentmaster and branch, the number of commits in master andthe branch since the branch was split off.
因此,无论你想使用master..
或master...
依赖于你是否想知道你提交了几次在您的分支,因为你把它分解关闭(master..
),或之间的差别目前主站和分公司,大师提交的数目和因为分支分支被分裂了。
回答by CharlesB
Assuming you branched from master, master..yourbranch
gives you the range of commits that are in yourbranch
but not in master.
假设您从 master 分支,master..yourbranch
为您提供yourbranch
在 master中但不在 master 中的提交范围。
Then you just have to list them one line each, and count the number of lines:
然后你只需要每行列出它们,并计算行数:
git log master..yourbranch --pretty=oneline | wc -l
回答by user1338062
Update: git rev-list now has --count
:
更新:git rev-list 现在有--count
:
git rev-list --count master..
With older git versions:
使用较旧的 git 版本:
git rev-list master.. |wc -l
rev-list lists revisions, and master..
refers to commits since current HEAD
diverged from master
.
rev-list 列出修订,并master..
指自当前HEAD
与master
.
回答by Martin G
If you want to see how many commits you or anyone else has made, starting from your current HEAD
, you can do:
如果您想查看您或其他任何人的提交次数,从您当前的 开始HEAD
,您可以执行以下操作:
git shortlog -sn
Example output:
示例输出:
490 Donald Duck
312 Some Developer
274 John Doe
144 Jane Doe
5 Leet Hacker