How to count the amount of git that affects a given subtree?

My version number looks like 0.1.3 and has two components:

  • 0.1 (tag)
  • 3 (fixed after the tag)

All this information is easy to get from git describe --tags .

For version 0.1.3, git describe might look like

 0.1-3-g53d4dec 

All this works fine, but I'm looking for the number of commits that affect only the given subtree, and not the entire repo. I do not want to change the version number if something inside examples/ or test/ has changed, but I do if something inside src/ has changed.

Basically, I'm looking for git describe --relative src/ , which works on the same lines as git log --relative .

+4
source share
3 answers

If you are working with a Git script, you should really use the plumbing commands instead of the porcelain commands (see git (1). In this case, the most likely candidate looks like git rev-list .

 git rev-list --full-history v0.1.. -- src | wc -l 
+4
source

It seems that the easiest way would be to write a short script - call git-describe to determine which tag you are using, and then do something like git log --pretty=%H $tag.. -- $path | wc -l git log --pretty=%H $tag.. -- $path | wc -l for counting commits.

+2
source

I understood that:

  git log $ tag .. --pretty =% h --relative $ path |  wc -l 

Or even simpler:

  git log --oneline $ tag .. - $ path |  wc -l 

Thank you guys from irc: //irc.freenode.net/git

I 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
        one 

1 commit the last tag to src/ . It is right.

+1
source

All Articles