Git – Rewrite History

There was time that you accidentally commit code to repository that you are not supposed to commit such as your password, or any secret code. I was looking for a way to revert the committed code that I have pushed in my repository. 

In git you can do it by rewriting the history. Below is how you can rewrite your history.

git rebase -i HEAD~3

HEAD~n : the n is the index of commit you want to rewrite from the HEAD. With the command above, it will give you the list of commits from the HEAD until the index 3. With this list you can choose between squash, drop, pick, etc.

After you rewrite the history then you can continue with 

git commit --amend
git rebase --continue

you can repeat these steps for each commit you change.