git中的分支提交数量 [英] Number of commits on branch in git

查看:128
本文介绍了git中的分支提交数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在这个例子中,我有一个小脚本,并且想知道我在当前分支上创建了多少次提交。 2 $ child

$ $ $ $ $ $ $ $ git checkout master
git checkout -b child
...
git commit -a
...
git commit -a

所以我想要的是

  commit_number = ... 
echo $ commit_number

感谢您的帮助。



 <$ c 解决方案

Git可以为您提供无需进一步shell脚本的提交数量。 $ c> git rev-list master .. --count

rev-列表是用于处理修订版本的半隐藏(未在 git help 中列出)命令。



As master .. 将列出从master和当前分支到当前分支 - count的提交会给你它们的计数。



如果你想要在两个修订版本之间提交数量,你可以使用主... 。详细说明:从主人到最近的共同祖先主人和当前分支(HEAD)之间,再次到当前分支。如果你将提交历史记录看成一棵树,你应该能够跟随来自共同祖先的两个分支。 master .. 另一方面只计算两个分支中的一个。



因此,无论您想使用 master .. master ... 取决于您是否想知道您提交了多少次提交 master .. ),或者当前 master和branch之间的区别,您的分支在分支分离后,在分支主中提交分支。


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:

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.

解决方案

Git can provide you with the number of commits without further shell scripting.

git rev-list master.. --count

rev-list is a semi-hidden (not listed in git help) command used to work with revisions.

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.

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.

So whether you want to use master.. or master... depends on whether you want to know how many commits you made in your branch since you split it off (master..), or the difference between the current master and branch, the number of commits in master and the branch since the branch was split off.

这篇关于git中的分支提交数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆