Skip to content
mnaoumov.dev
Go back

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 is 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

or

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…


Share this post on:

Previous Post
git - fight with pull merges
Next Post
git checkout on bare repo