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
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.
git stash– lets make sure there are no debris left!
git rebase -i 11233^– make sure you put the
^at the end, otherwise the following steps would fail miserably.
- 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
editso that it looks like:
edit 11233 [#222] Your faulty commit message here pick 234234 [#222] This commit has no problem
- 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!
- Once set,
git commit --amendand modify the commit message too, if you want
- All set, and you can now execute
git rebase --continueand you will be back in your commit
- Push your changes to your
git push -f myfaultybranch
- In case you screw up in between, please do
git reset --hard 5514134and you will be reverted back 🙂
Hope it helps! Lets rewrite history! Found something wrong ? Please do comment!