from–https://stackoverflow.com/questions/53471209/git-diff-noindex-exclude-files
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)
1 Answer
7
The pathspec :(exclude) and its short form :! or :^ is available only within a Git working tree.
So:
- either, as commented, you can put it in a (temporary) git local repo (git init . + git add) or
- you would need to do your
git diff --no-index
in afind -exec
command with exclude directives.
- 1Is 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?
- 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
- In the end, I followed this answer to a very similar question, which recommended making one repo a remote of the other.
- @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
Nov 26, 2018 at 1:26
Mar 9, 2020 at 15:26