Home > OS >  How to count git commit numbers which contains filename (*_test.cpp)?
How to count git commit numbers which contains filename (*_test.cpp)?

Time:01-22

git log --grep "xxx" only search commit log while git log -- *_test.cpp only shows commit just contains *_test.cpp.

Is there a way to show commits which contains filename (*_test.cpp)? I'd like to count both commit1 and commit2 case.

commit1: 
    /path_a/file_a.cpp; 
    /path_a/file_b.cpp; 
    /path_b/file_a_test.cpp; 

commit2: /path_c/file_b_test.cpp

commit3: /path_d/file_d_test.cpp
    /path_e/file_e_test.cpp

Thanks.

CodePudding user response:

I think using the ** wildcard will get you what you want:

git log '**/*_test.cpp'

** matches any number of directories. For more details, see the documentation.

CodePudding user response:

Your title says count, your question body says show.

Count:

git rev-list --count @ -- \*_test.cpp

list:

git rev-list @ -- \*_test.cpp

show:

git log @ -- \*_test.cpp

and I'd recommend adding either --no-merges or --first-parent to avoid redundantly listing every merge that forwarded changes along with the commit that made it.


git log -- *_test.cpp only shows commit just contains *_test.cpp

That's not how git log works for me, and its not how it's documented to work. Check your evidence, I think you're misunderstanding whatever led you to say that, for instance, in my git repo:

$ git log -10  --pretty=format:  --name-only --no-merges @ -- \*-*.c
refs/files-backend.c

builtin/cat-file.c

builtin/cat-file.c

fmt-merge-msg.c

t/helper/test-drop-caches.c

stable-qsort.c

builtin/update-index.c
read-cache.c

builtin/receive-pack.c

builtin/cat-file.c
builtin/rev-list.c

ref-filter.c
$

but adding the --full-diff option gives a much longer list of files touched by those commits.

  •  Tags:  
  • Related