Skip to content

Instantly share code, notes, and snippets.

@mayra-cabrera
Created January 27, 2015 17:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayra-cabrera/33b88ccaa383ebae1de9 to your computer and use it in GitHub Desktop.
Save mayra-cabrera/33b88ccaa383ebae1de9 to your computer and use it in GitHub Desktop.
Remove sensitive data from commits history

Imagine that you want to erase completely the file under config/secrets.yml from your commits history

Move to the working directory where the config folder is placed

cd dummy/

Run git filter-branch, forcing (--force) Git to process—but not check out (--index-filter)—the entire history of every branch and tag (--tag-name-filter cat -- --all), removing the specified file (git rm --cached --ignore-unmatch Rakefile) and any empty commits generated as a result (--prune-empty). Note that you need to specify the path to the file you want to remove, not just its filename. The previous was taken from Github documentation

git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch config/secrets.yml' \
--prune-empty --tag-name-filter cat -- --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment