Delete Files From The History In Git
We need to delete files from the history of git when we commit some files which shouldn’t be committed.
Steps
There are two steps to delete files from git.
Delete Files
There are two options for us to delete files.
- Delete a single file
1 | git filter-branch --index-filter 'git rm --cached --ignore-unmatch Path/YourFileName' |
- Delete a folder
1 | git filter-branch --index-filter 'git rm --cached -r --ignore-unmatch ThePathOfTheFolders' |
Push change to remote repo
The command to push change to remote repo is simple. The command is git push -f.
Clear Local Git
1 | rm -rf .git/refs/original/ |
This blog is under a CC BY-NC-SA 3.0 Unported License
Link to this article: https://younggod.netlify.app/2020/11/11/practice/deletFileFromGit/