Rewriting Git history, correcting a previous commit in your PR

This blog post should be dedicated to my mentor jaragundeΒ at Igalia, as he had been the one pointing me out to go back again and again to that wrong PR, I made, and correct it. The first time I did, it sounded a bit confusing, and here you go!

You are working on an XYZ Pull Request having a series of commits namely 234234, 11233 and the latest one being 5514134. Your mentor tells you there is a mistake in 11233, and you want to go back to that commit, and correct the same.

Alright, so lets assume you are in the branch myfaultybranch with the git log showing up 5514134 at the top.


  1. git stash – lets make sure there are no debris left!
  2. git rebase -i 11233^ – make sure you put the ^ at the end, otherwise the following steps would fail miserably.
  3. on the screen that come up, you will have the other commits too listed, looking like
    pick 11233 [#222] Your faulty commit message here
    pick 234234 [#222] This commit has no problem

    Edit the first line, from pick to edit so that it looks like:

    edit 11233 [#222] Your faulty commit message here
    pick 234234 [#222] This commit has no problem
  4. Save, and you are in a state where you are one step before committing 11233. Yay! Now make all your changes you want, correct all the mistakes at your ease!
  5. Once set, git add and git commit --amend and modify the commit message too, if you want
  6. All set, and you can now execute git rebase --continue and you will be back in your commit 5514134. Yay!
  7. Push your changes to your origin via a git push -f myfaultybranch
  8. In case you screw up in between, please do git reset --hard 5514134 and you will be reverted back πŸ™‚

Hope it helps! Lets rewrite history! Found something wrong ? Please do comment!


Git-Review troubleshoot:- Multiple commits error

Playing with code review tools like gerrit and git-review, one of the common error a user can hit with is the Multiple Commits problem.
* You have checked out a new branch, made your edits, added the files and did git commit with necessary commit message.
* You give the command
git review
and git complains that you are going to submit a number of commits.
A sample error screen after giving git review
* You can see your commit on the top of the list with HEAD along with commit id.
* give the following in order
$ git diff HEAD^ This will list down your latest commit. Make sure thats the one you need to commit.
* $ git rebase -i origin/master
This would bring up an interactive git-rebase in your default text editor.
* Delete all the lines, except the line showing your commit message.
* Close the editor. Do $ git review
and it works πŸ™‚ Thanks!