14

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?

Mariano
  • 1,357
  • 3
  • 17
  • 30
  • 1
    Look at http://stackoverflow.com/questions/5685007/making-git-log-ignore-changes-for-certain-paths/21079437#21079437 – David Neiss Jul 07 '16 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 Jul 07 '16 at 16:56

2 Answers2

16

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...]
G. Sylvie Davies
  • 5,049
  • 3
  • 21
  • 30
6

If you have multiple folders to ignore

git show -- . ':!some/path' ':!some/other/path'
John Muraguri
  • 426
  • 7
  • 6