git diff noindex exclude files



Does any one how to exclude files when comparing folders with git diff –no-index ? It seems this option


does not work with no-index (outside working tree)

1 Answer


The pathspec :(exclude) and its short form :! or :^ is available only within a Git working tree.


  • 1
    Is it documented that pathspecs are only available within a Git working tree? Does this mean pathspecs are NEVER available with –no-index, even if the command is run from within a Git working tree?

    Aug 11, 2020 at 13:43

  • @JosiahYoder Not sure actually: what did you try?

    – VonC

    Aug 11, 2020 at 15:13

  • I tried cd’ing into one of the repos to be compared, then tried creating a temporary git repo. Both used --no-index, and both simply showed usage . I think --no-index simply doesn’t work with :!.git

    Aug 11, 2020 at 15:23

  • In the end, I followed this answer to a very similar question, which recommended making one repo a remote of the other.

    Aug 11, 2020 at 15:25

  • @VonC I dont think the second option you mentioned works as you think it does. At least the following doesn’t work for me: find . -name '*.txt' -exec git diff --stat --no-index git_test1/*.txt git_test2/*.txt \; Any tipps or snippets for the second option would be appreciated.

    – Sam Fed

    May 20, 2021 at 13:48