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

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

问题描述

我正在编写一个小脚本,想知道自当前分支创建以来我在当前分支上进行了多少次提交.

I'm writing a small script and want to know how many commits I made on a current branch since it was created.

在这个例子中,我将在 child 上进行 2 次提交:

In this example I'd have 2 commits made on child:

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

所以我想要的是

commit_number = ...
echo $commit_number

推荐答案

Git 可以为您提供提交次数,而无需进一步编写 shell 脚本.

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

git rev-list master.. --count

rev-list(列在 git help -a) 用于处理修订.

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

由于 master.. 将列出从 master 的基础和当前分支到当前分支的提交,--count 将为您提供它们的计数.

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....详细说明:在从 master 到 master 和当前分支(HEAD)的最新共同祖先之间,再到当前分支.如果您将提交历史可视化为一棵树,您应该能够跟踪来自共同祖先的两个分支.master.. 另一方面,只会计算两个分支中的一个.

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..),或者 当前 master 和 branch 之间的差异,master 和 中的提交次数em> 分支被拆分后的分支.

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天全站免登陆