Handy one-liners - remove a file from git repository
Some time ago you committed a file - say file.txt - to a git repository. Then you realised that this file does not have to be committed and should rather be ignored. Normally, you would just delete the file, and run git commit -a, but you do not want to delete the file, you just want git to forget about its existence. Here is the trick:
git rm --cached file.txt
Before:
$ git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: file.txt #
After:
$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # deleted: file.txt # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # file.txt










