Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 2

How do I use 'git ls-tree' to limit to certain filetypes?

Solved! Go to Solution.
git ls-tree -r --name-only HEAD | while read filename; do
  echo "$(git log -1 --format="%ai" -- $filename) $filename"
done

 

The above snippet will show me the last-modified dates of files in the current commit.

 

Is there a way to return only the jpg, gif, and css files?

 

Ideally, I'd love to know how I get a list of those and show only the ones that were modified since the last commit, but I'd settle for a list that limited to just those filetypes.

 

 

1 Reply
Solution
Copilot Lvl 2
Message 2 of 2

Re: How do I use 'git ls-tree' to limit to certain filetypes?

```

git ls-tree -r --name-only HEAD | grep ".\.css" | while read filename; do
echo "$(git log -1 --format="%ai" -- $filename) $filename"
done

```

I've realized I can add a grep to my request and limit to the filetype that way.  Now I want to know how can I limit my search to just specific folders in the file system?  It would speed it up a lot if I can limit where I search.

 

I kept digging... I worked out you can just add the path.  You know what they say, when all else fails, RTFM.

 

example:

 

git ls-tree -r --name-only HEAD src/main/webapp/assets/master-template/ | grep ".\.css" | while read filename; do
echo "$(git log -1 --format="%ai" -- $filename) $filename"
done