Git, remove unwanted data from history
Posted on 23 Nov 2014 in Programming • 1 min read
Recently I put unwanted data (a password) in one of my git commit. This commit was not push to an public server (like github or bitbucket) therefore there was no real security breach other than my git history.
The problem was to remove the data by rewriting the git history, I search on the internet and found and interesting command using git filter-branch To rewrite the git history use the following command:
git filter-branch --tree-filter 'git ls-files -z "*.py" |xargs -0 perl -p -i -e "s#(PASSWORD1|PASSWORD2)#youPassowrd#g"' -- --all
This command will just change the history of python files (.py) and replace "PASSWORD1" and "PASSWORD2" whit "youPassword".
WARNING rewriting git history is dangerous, make a backup before doing anything.
You can found a short version in my notes.