Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git show: exclude a directory when checking a past commit's changes

Tags:

git

I usually check the changes introduced by a commit with the git show command. This works well, except when I'm only interested in the changes introduced in a subset of the changed files.

Is there something like git show --exclude some/path that will do this out of the box?

like image 299
Mariano Avatar asked Jul 07 '16 16:07

Mariano


1 Answers

Translating @DavidN's comment into an answer, here's what you get (people may not realize that "git log" and "git show" take all the same options):

git show -- . ':!some/path'

Requires git 1.9 or newer.

Here's a example showing it in use against the php github repo:

git remote -v
origin  https://github.com/php/php-src.git (fetch)

Here's a "--name-only" git show without the exclusion:

git show -p -m --first-parent --name-only --oneline e231830f1683e
e231830 Merge branch 'PHP-5.6.18' into PHP-7.0.3
ext/phar/dirstream.c
ext/phar/tar.c
ext/phar/tests/bug71331.phpt
ext/phar/tests/bug71331.tar
ext/phar/tests/bug71354.phpt
ext/phar/tests/bug71354.tar
ext/phar/tests/bug71391.phpt
ext/phar/tests/bug71391.tar
ext/phar/tests/bug71488.phpt
ext/phar/tests/bug71488.tar
ext/standard/iptc.c
ext/standard/streamsfuncs.c
ext/standard/tests/file/stream_rfc2397_002.phpt
ext/standard/tests/network/socket_get_status_basic.phpt
ext/standard/tests/streams/bug71323.phpt
[etc...]

And here it is excluding "ext/phar":

git show -p -m --first-parent --name-only --oneline e231830f1683e -- . ':!ext/phar'
e231830 Merge branch 'PHP-5.6.18' into PHP-7.0.3
ext/standard/iptc.c
ext/standard/streamsfuncs.c
ext/standard/tests/file/stream_rfc2397_002.phpt
ext/standard/tests/network/socket_get_status_basic.phpt
ext/standard/tests/streams/bug71323.phpt
[etc...]
like image 183
G. Sylvie Davies Avatar answered Nov 15 '22 05:11

G. Sylvie Davies