0%

How to make git forget tracked files

git rm -r --cached . && git add . && git commit -am "Remove ignored files"
git update-index --skip-worktree

Remove tracked file from the index

1
2
3
4
5
6
7
8
9
# file
git rm --cached <file>

# folder
git rm -r --cached <folder>

# remove all then add back
git rm -r --cached .
git add .

Commit

1
git commit -am "remove ignored files"

One-Liner

1
git rm -r --cached . && git add . && git commit -am "Remove ignored files"

Another Choice - skip-worktree

--skip-worktree is for modified tracked files that the user don't want to commit anymore and keep --assume-unchanged for performance to prevent git to check status of big tracked files.

1
2
3
4
git update-index --skip-worktree <file>

# cancel
git update-index --no-skip-worktree <file>

References

  • https://stackoverflow.com/questions/1274057/how-do-i-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore
  • https://stackoverflow.com/questions/13630849/git-difference-between-assume-unchanged-and-skip-worktree
  • https://fallengamer.livejournal.com/93321.html