1

So I managed to perform a rebase and pushed the changes to Gitlab but now I am getting errors and would like to cancel the whole rebase and go back to where I started. I am working on a "feature-branch" and I did the rebase to "develop" branch.

What I did was:

  • Git checkout feature-branch
  • Git rebase develop
  • Git push -f origin feature-branch

So now both my local branch and the remote branch contains the changes from the rebase. Is there anyway I could cancel the whole rebase and push -f and try to do it again? Thanks!

  • Possible duplicate of [Undoing a git rebase](https://stackoverflow.com/questions/134882/undoing-a-git-rebase) – phd Jul 17 '18 at 19:34

2 Answers2

4

you could check out git reflog https://git-scm.com/docs/git-reflog

git reflog feature-branch

and then find the latest good commit and then

git reset -- hard 129e6d3 

where that number is the commit ref

EDIT:

after a google search, I found this, https://medium.com/@shreyaWhiz/how-to-undo-a-mistaken-git-rebase-life-saver-2977ff0a0602 which seems like your problem

3

You can find the commit on the branch before the rebase happened, then reset it back - (git log or git reflog will help that). Also GitLab has a network tab which should allow you to see this easily.

example of git reflog as that one will probably be the easiest:

git reflog feature-branch

The above will give you some output like:

73d836b feature-branch@{0}: rebase finished: feature-branch onto e806e41f1fe22624e6546abd65c332c934214891
129e6d3 feature-branch@{1}: commit: Commit message

Get the commit ref from the above output (pick the point where the latest good commit was)

git reset --hard {commitRef}
git push -f // this will push your branch back to how it was before rebase
Josh Stevens
  • 3,943
  • 1
  • 15
  • 22