find all git commits for a file type
Asked Answered
Z

2

9

its pretty simple to find all the commits containing a particular file.

git log -- .\Database\Tables\sometable.sql

but is there a simple way to find all the commits for a file type (recursively down child directories?) or will I need to write a script to do this?

(conceptually...)

git log -- .\Database\*.sql --recursive
Zachary answered 14/10, 2012 at 23:36 Comment(0)
E
9

It appears that perhaps you just need to escape the * so that it doesn't get expanded by the command line. It would seem that you are on Windows so... but I am on Linux and tested like so:

git init
mkdir -p blue/red/green
touch blue/red/green/colors
git add blue/red/green/colors
git commit -m "colors and dirs"
touch blackAndWhite
git add blackAndWhite
git commit -m 'b&w'
git log -- \*ors

The result on the last git log is:

commit 8fdb718b5b616dd495c00eb7a6d123c33f7707e5
Author: <snipped>
Date:   Sun Oct 14 19:49:43 2012 -0400

    colors and dirs

On the Windows escaping of *... perhaps put it in either single or double quotes? I'll add if I figure something out.

Electromyography answered 15/10, 2012 at 0:4 Comment(6)
Just realized I do have my Windows laptop with Git here from work... in a Git bash window my 'script' above works fine. Perhaps your use of `` as a path delimiter is just a slip-up? Or you have some other Windows Git client than I do?Electromyography
Yeah, using posh-git (powershell)Zachary
ok, so from the bash prompt it does work as I wanted. Must be a powershell thing like you suggest.Zachary
If you can figure out how to escape the * in the powershell so it doesn't expand it, it should work there as well. I noticed that if the wildcards don't match anything in the current directory (Linux bash or Git bash) then they do get passed to git log and it does it's thing with them. The escape is only really necessary if the wildcard does match something.Electromyography
annoying that I can't figure out how to escape the * in PS, but at least I can do what I need from bash, that'll have to do for now...unless someone knows how to escape the * <hopeful/>Zachary
Looking around it may be the accent grave/backtick `. Luck would have it that I'm not quite sure how to escape the backtick here on stackoverflow though. serverfault.com/questions/47811/…Electromyography
V
1

I wanted to see all contributions by type for all users in my repository. I found a Ruby package that will do this, git fame (here). If you type git fame . --by-type it will output something like this:

enter image description here

Vincenty answered 11/8, 2017 at 19:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.