Search code examples
gitfindfilenames

Find commits that modify file names matching a pattern in a GIT repository


I'd like to find commits in my code base that add video files to throw them out. Is there a way to look for these files in git ?

For example let's say all videos have a filename ending with the extension .wmv ; I'd like to find all commits introducing these files and get rid of them with a fixup or something.

Any ideas ?


Solution

  • You can use git log with a pathspec:

    git log --all -- '*.wmv'
    

    This will get you all commits which make changes to .wmv files. Yes, this will descend into subdirectories too (and you have to surround your pathspec with single quotes to protect it from being expanded by your shell; otherwise the wildcard will not be passed to Git, but only the expanded list of file names).

    If you are only interested in commit hashes (scripting etc.) use the git rev-list machinery directly:

    git rev-list --all -- '*.wmv'
    

    Under Windows, it might be required to use double quotes instead of single quotes around the pathspec, i.e. "*.wmv"