Last Updated: February 25, 2016
·
517
· shaneriley

Listing one or more files under Git version control

I just had to locate swap files that someone had mistakenly checked in over the course of the last 30 commits, and figured there was a way to do that without git log. Turns out, there is. This git command combined with a grep for the file name or partial file name (like a .swp extension) will return you a nice list of files matching your description.

git ls-tree --full-tree -r HEAD | grep <filename or string to search for>

For example, to list all .swp files, you'd run

git ls-tree --full-tree -r HEAD | grep .swp