Back

Explore Courses Blog Tutorials Interview Questions
+4 votes
1 view
in DevOps and Agile by (29.3k points)
edited by

Does anybody know how to easily undo a git rebase?

The only way that comes to mind is to go at it manually:

  • git checkout the commit parent to both of the branches
  • then create a temp branch from there
  • cherry-pick all commits by hand
  • replace the branch in which I rebased by the manually-created branch

In my current situation, this is gonna work because I can easily spot commits from both branches (one was my stuff, the other was my colleague's stuff).

However, my approach strikes me as suboptimal and error-prone (let's say I had just rebased with 2 of my own branches).

Any ideas?

Clarification: I'm talking about a rebase during which a bunch of commits was replayed. Not only one.

1 Answer

+5 votes
by (50.2k points)
edited by

The easiest way to find the head commit of a branch is using the following commands.

git reflog

and to reset the current branch to it with -- hard option, if suppose old commit was [email protected]{1} in reflog then follow the commands

git reset --hard [email protected]{1}

If you are using windows system then you need to quote it “[email protected]{1}”.

History of the old commit  can find in 

git log [email protected]{1} 

If you've not disabled per branch reflogs 

git reflog [email protected]{1}

As rebase detaches the branch head before reattaching to the final head.

For more commands like this please go through the following tutorial that will help you understand the git

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...