Skip to content

Instantly share code, notes, and snippets.

@liitfr
Created July 14, 2017 19:20
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liitfr/39c4b0df7be7bfdde1273125f4169dbb to your computer and use it in GitHub Desktop.
Save liitfr/39c4b0df7be7bfdde1273125f4169dbb to your computer and use it in GitHub Desktop.
you accidentally commited your .env file in a previous commit, and you want it to disappear ? 🕵

Answer

Execute this code in your repository

git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch .env' \
--prune-empty --tag-name-filter cat -- --all

don't forget to replace .env by expected name.

@maaajo
Copy link

maaajo commented May 13, 2020

Thanks, worked like a charm!

@BearJS
Copy link

BearJS commented Jan 13, 2021

Thanks, worked for me

@bjorntirsen
Copy link

My .env file still shows in the commit on GitHub after running above code.

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