git undo

I was approached with question how can we undo changes we made using git pull –rebase

I will answer the question. The solution as applicable not only for this scenario, but for different ones such as undo a normal rebase or even undo an incorrect reset.

Let’s talk about git pull –rebase

Imagine for whatever reason I want to undo it, and revert to the state it was before

We just type

git reflog

and then we get

69d936d HEAD@{0}: rebase finished: returning to refs/heads/mybranch
69d936d HEAD@{1}: pull --rebase: Hello world!
e96d70c HEAD@{2}: checkout: moving from mybranch to e96d70c47733096fa7372225b47638e2c1bd0fe4^0
0adf1c8 HEAD@{3}: commit: Hello world!

First three lines represent a pull –rebase changes. Fourth line represents the state before this command

So what we have to do is just

git reset --hard 0adf1c8


git reset --hard "HEAD@{3}"

(note that quotes are required only if you execute the command from PowerShell)

After that we rolled back to the state before our pull –rebase.

Simple and powerful…


About mnaoumov

Senior .NET Developer in Readify
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s