How do I get the Git commit count?

2019-01-01 09:22发布

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

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

I currently do like that, on 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. Just read a file or a directory structure...

20条回答
听够珍惜
2楼-- · 2019-01-01 10:21

You can try

git log --oneline | wc -l

or to list all the commits done by the people contributing in the repository

git shortlog -s
查看更多
回忆,回不去的记忆
3楼-- · 2019-01-01 10:21

git config --global alias.count 'rev-list --all --count'

If you add this to your config, you can just reference the command;

git count

查看更多
登录 后发表回答