Remove ignored files in git
One command to use for removing ignored files that are checked-in
Removing ignored files from git
If you ever were in the situation that already checked-in files or directories in git should be removed, there’s a single command that does exactly this. This command avoids deleting the data, commits the deletion and adds the same data afterwards again.
# In this example, the 'bin'-directory # gets removed from git. Note that this # operation doesn't remove the file # itself, only its reference in git. git rm -r --cached bin # Same command, for the file 'log.ts'. git rm -r --cached log.ts
Works also for already checked-in data
This command also removes the specific file or directory from the git-tree if the data has been added before it was defined in the gitignore-file. Of course, the real file or directory won't get deleted, only its reference in git.