Undoing a git rebase
It is a common practice to rebase the main branch to your current branch when there is a change or rebasing to squash multiple commits into single to group the certain changes together. Until you force push the changes you made, it’s fairly easy to get back to original state from which you started rebasing by using this command:
git rebase --abort
But there are times when you complete rebasing the branch and realize something isn’t working as expected due to merge conflicts and all when rebasing. On such conditions, the easiest way would is to find the head commit of the branch as it was immediately before the rebase started in the reflog:
git reflog
and to reset the current branch to it (with the usual caveats about being absolutely sure before reseting with the –hard option).
Suppose the old commit was HEAD@{7} in the ref log:
git reset --hard HEAD@{7}
In Windows, you may need to quote the reference:
git reset --hard "HEAD@{7}"
Once you verify everything is back to normal, you can just force push your branch to save the current state on git.
Note: if you want to check the history of any old head then you can just run git log HEAD@{7} (Windows: git log “HEAD@{7}”
This is how, you can revert your branch to it’s previous state before rebasing. Hopefully, this might turn out to be useful… 🙂
Further more, you can get more details on this link:
https://stackoverflow.com/questions/134882/undoing-a-git-rebase