Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter `git show <commitId>` result with file extension

Tags:

git

file

patch

Consider a very big changeset. Upon doing git show <sha1>, you get changes related to all files. But I am interested only in changes made to .cpp files, rest files are not useful for my analysis.

How can I filter them out of git show result?

Any command or option.

like image 612
Saurav Sahu Avatar asked May 21 '17 06:05

Saurav Sahu


Video Answer


3 Answers

git show -- *.cpp works. Without --, the glob seems unable to work properly.

like image 55
ElpieKay Avatar answered Oct 18 '22 21:10

ElpieKay


Answer given by @ElipieKay in comment section worked for me.

Prints file names having .cpp extension.

git show --name-status 29a9f891fd -- *.cpp      

Display the changes done to files with .cpp extension.

git show 29a9f891fd -- *.cpp
like image 24
Saurav Sahu Avatar answered Oct 18 '22 20:10

Saurav Sahu


You can filter the diff which git show outputs by providing paths or patterns to match. So in your case:

git show "*.cpp"

You need to use the appropriate quoting for your shell to ensure that Git sees the wildcard (*.cpp) and that it isn't expanded by you shell first.

like image 41
CB Bailey Avatar answered Oct 18 '22 22:10

CB Bailey