Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

git - 我如何获得Git提交计数?(How do I get the Git commit count?)

I'd like to get the number of commits of my Git repository, a bit like SVN revision numbers.

(我想得到我的Git存储库的提交数量,有点像SVN版本号。)

The goal is to use it as a unique, incrementing build number.

(目标是将其用作唯一的递增构建号。)

I currently do like that, on Unix/Cygwin/msysGit:

(我目前在Unix / Cygwin / msysGit上喜欢这样:)

git log --pretty=format:'' | wc -l

But I feel it's a bit of a hack.

(但我觉得这有点像黑客。)

Is there a better way to do that?

(有没有更好的方法呢?)

It would be cool if I actually didn't need wc or even Git, so it could work on a bare Windows.

(如果我实际上不需要wc甚至Git,那将是很酷的,所以它可以在裸Windows上运行。)

Just read a file or a directory structure...

(只需读取文件或目录结构......)

  ask by Splo translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To get a commit count for a revision ( HEAD , master , a commit hash):

(获取修订的提交计数( HEADmaster ,提交哈希):)

git rev-list --count <revision>

To get the commit count across all branches:

(要获取所有分支的提交计数:)

git rev-list --all --count

I recommend against using this for build identifier, but if you must, it's probably best to use the count for the branch you're building against.

(我建议不要将它用于构建标识符,但如果必须,最好使用你正在构建的分支的计数。)

That way the same revision will always have the same number.

(这样,相同的修订版将始终具有相同的编号。)

If you use the count for all branches, activity on other branches could change the number.

(如果对所有分支使用计数,则其他分支上的活动可能会更改该数字。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...