0

I have several target subdirectories in my project that I do not want to track. So I removed them all with:

find . -type d -name 'target' -print0 | xargs -0 git rm --cached -r --

I also added ./*/target/ to my .gitignore file.

I then ran git add -A and it appears all of my target subdirectories were tracked and I had to remove them again.

Does git add -A simply not respect .gitignore? Will I have to run git add with a different option?

brianxk
  • 63
  • 1
  • 6
  • 1
    Had you previously committed these files? If so, this has been asked and answered a number of times already, e.g. https://stackoverflow.com/questions/1274057/how-do-i-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore – IMSoP Feb 06 '23 at 22:20
  • Yes but I removed them from the index with the aforementioned `find` command in the OP. If I run a `git commit` after removing them, the files are successfully untracked. It's only when I do `git add` after untracking the files that they get re-tracked again. – brianxk Feb 06 '23 at 22:23

1 Answers1

0

Turns out I had the incorrect format in my .gitignore file.

I replaced

./*/target/

with

*/target/**

*/target/** will recursively ignore all the contents of all */target subdirectories.

brianxk
  • 63
  • 1
  • 6