How to ignore the contents of a previously tracked directory in git?

116 views Asked by At

I have seen this post about no longer tracking a previously tracked file, but here is my situation.

I previously committed a directory. I now want to untrack everything in that directory but still track the directory itself.

I have added /auto-save-list/* to the .gitignore file (the directory I am trying to ignore is the auto-save-list directory in the root of the project, and I have run git rm --cached but I still have multiple filed from that directory that show up as new when I go to make a commit. Similarly the files show up in my origin repo.

Can someone help me ignore the contents of the previously tracked file?

1

There are 1 answers

0
VonC On BEST ANSWER

This should be enough:

git rm -r --cached auto-save-list/
echo "/auto-save-list/" > .gitignore
git add .gitignore
git commit -m "Records untracking of /auto-save-list/ folder"

No need for '*'

If you still need the directory to be there (versioned in the Git repo, even though Git doesn't track an empty folder), add a dummy file in it.

touch auto-save-list/.keep
git add -f auto-save-list/.keep
git commit -m "Record auto-save-list/ folder, while ignoring its content"