Skip to content

Instantly share code, notes, and snippets.

@goldzulu
Created June 21, 2022 17:29
Show Gist options
  • Save goldzulu/6e364ac553acae51782e109a21852b35 to your computer and use it in GitHub Desktop.
Save goldzulu/6e364ac553acae51782e109a21852b35 to your computer and use it in GitHub Desktop.
Completely remove A File from GIT History

Completely remove a file from Git history permalink

To remove the file altogether, we can use the following command. Assuming .env is the file to remove

git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch .env" HEAD You will get some warnings about this messing up your history as this goes through your whole history and 100% removes its occurrence.

To push this, you have to run the following command.

git push --force If we look at our history, we can still see the commits that include this .env file, but the content is empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment