My version number looks like 开发者_如何学Go0.1.3 and has two components:
- 0.1 (the tag)
- 3 (commits after tag)
All this information easy to obtain from git describe --tags
.
For version 0.1.3 git describe
may look like
0.1-3-g53d4dec
All of this works fine, but I'm looking for the number of commits affecting only a given subtree, not the whole repo. I don't want to change the version number if something within examples/
or test/
changed, but I do if something within src/
changed.
Basically, I'm looking for git describe --relative src/
that works along the same lines as git log --relative
.
If you are scripting Git, you should really use the “plumbing” commands instead of the “porcelain” commands (see git(1). In this case, the most likely candidate seems like git rev-list
.
git rev-list --full-history v0.1.. -- src | wc -l
It sounds like the easiest thing to do would be to write a short script - call git-describe to determine what tag you're basing off of, then do something like git log --pretty=%H $tag.. -- $path | wc -l
to count the commits.
I came up this this:
git log $tag.. --pretty=%h --relative $path | wc -l
Or even simpler:
git log --oneline $tag.. -- $path | wc -l
Thanks guys from irc://irc.freenode.net/git
I've tested:
git init Initialized empty Git repository in /private/tmp/test/.git/ $ touch a $ git add a $ git commit -m 'first' [master (root-commit) f8529fc] f 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 a $ git tag -m 'F' v0.1 $ git tag v0.1 $ mkdir src $ touch src/b $ git add src/b $ git commit [master a5345cd] B 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/b $ git log --oneline $tag.. -- $path | wc -l 1
1 commit after last tag within src/
. That's right.
精彩评论