How to rollback or remove last commit in remove Git


This is common thing can happen when we push bad commit and want to rollback into previous commit. Please try this in your own branch before apply into production / master.

Try with “git log” :

1
2
3
4
5
6
7
8
9
10
11
commit 10a8e361b35dd8131cb1ba3e606aad35d0d0f267
Author: Somebody
Date:   Fri Dec 26 13:02:33 2014 +0700

     Bad commit here

commit f89150c864cd4725a25995efd233f5beab7fc25d
Author: Somebody 2
Date:   Fri Dec 26 12:21:37 2014 +0700

    Stable version

So, we want to rollback commit from top into bottom. The easy way to do is :

1
git push -f origin <your-stable-commit>:<your-branch>

Example:

1
git push -f origin f89150c864cd4725a25995efd233f5beab7fc25d:development

Then update your local by:

1
git reset –hard origin/development

If this happened in your local but not submitted in remote yet, then you can reset it by:

1
git reset –hard HEAD~<number-of-rollback>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.