13

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

':(exclude)*.min.css'

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

jani_r
  • 637
  • 1
  • 7
  • 18

1 Answers1

7

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

So:

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 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? – Josiah Yoder Aug 11 '20 at 13:43
  • @JosiahYoder Not sure actually: what did you try? – VonC Aug 11 '20 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` – Josiah Yoder Aug 11 '20 at 15:23
  • In the end, I followed [this answer](https://stackoverflow.com/a/50606259/1048186) to a very similar question, which recommended making one repo a remote of the other. – Josiah Yoder Aug 11 '20 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 '21 at 13:48
  • @SamFed The second option was about using exclude directive. I don't see them in your command. Can you ask a separate question, with more details on your current setup? ( OS, shell, Git version) – VonC May 20 '21 at 14:14