Undo Last Published Commit in GIT

Today I’m refactoring my old code in my project and unexpectedly my refactor code messed up my apps. So I have to go back to my previous commit.

I know we can simply use.

$ git reset --hard your_commit_hash

But I couldn’t use that, because my previous commit already pushed to my repository.
Here is how to fix that using revert.

$ git log --oneline -5

a8031a3 Refactor tab host to swipable tabs for history
32d5856 Polishing order history progress # I need to go back here
3a984b0 Remove obsolete order handler
2b09868 Init order history
8102df9 Create order history pojo

$ git revert a8031a3 # commit hash that you need to remove.

Then it will remove my refactor commit and create new commit for revert.

c0cd60f Revert "Refactor tab host to swipable tabs for history" # new commit
a8031a3 Refactor tab host to swipable tabs for history
32d5856 Polishing order history progress
3a984b0 Remove obsolete order handler
2b09868 Init order history

Last step, what you need todo just push your commit. 😀

Thanks to Rezha 😀

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s