To ignore any changes to all the files (of a certain type) in a directory, I had to combine some of these approaches, otherwise the files were created if they didn't previously exist.
In the below, "excludedir" is the name of the directory that I wish to not watch changes to.
First, remove any existing new files from your change tracking cache (without removing from your file system).
git status | grep "new file:" | cut --complement -d " " -f1-4 | grep "^excludedir" | xargs git rm --cache
You can do the same with modified:
. renamed:
is a bit more complicated, as you'll have to look at the post ->
bit for the new filename, and do the pre ->
bit as described for deleted:
below.
deleted:
files prove a bit more complicated, as you can't seem to update-index for a file that doesn't exist on the local system
echo .deletedfiles >> .gitignore
git status | grep "deleted:" | cut --complement -d " " -f1-4 | grep "^excludedir" > .deletedfiles
cat .deletedfiles | xargs -d '\n' touch
cat .deletedfiles | xargs -d '\n' git add -f
cat .deletedfiles | xargs -d '\n' git update-index --assume-unchanged
cat .deletedfiles | xargs -d '\n' rm
The last command in the list above will remove the files again from your file system, so feel free to omit that.
Then, block change tracking from that directory
git ls-files excludedir/ | xargs git update-index --skip-worktree
git update index --skip-worktree excludedir/