15

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?

2
  • 1
    Look at stackoverflow.com/questions/5685007/… Commented Jul 7, 2016 at 16:41
  • @DavidN Thank you, I didn't think to search for similar options on other commands. I've also been told that git show accepts the same arguments as git diff
    – mariano
    Commented Jul 7, 2016 at 16:56

3 Answers 3

20

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...]
6

If you have multiple folders to ignore

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

I prefer to use the '*wildcard*' syntax rather than full paths usually, and this works to just negate it

git show '!:*wildcard*'

Not the answer you're looking for? Browse other questions tagged or ask your own question.