Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undo a git rebase

Using intelliJ i am working on a feature branch, i wanted to integrate the changes my team did on master into my branch, but i messed it up.
I checked out master, from Git pop up i selected the feature branch and selected 'rebase current onto selected' thinking that this would have added the changes from master on top of feature branch, unfortunately it happened the opposite. So what i would like to do now is to undo this rebase on master, i would like to bring master back to the latest head commit.
Any advice?
I read that rebasing creates a new commit but i think that that did not go through because i have conflicts, when from git command line i run git status from master i see:

You are currently rebasing branch 'master' on 'FEATURE/....'.
  (fix conflicts and then run "git rebase --continue")
  (use "git rebase --skip" to skip this patch)
  (use "git rebase --abort" to check out the original branch)

no changes added to commit (use "git add" and/or "git commit -a")

like image 262
JBoy Avatar asked Aug 27 '26 17:08

JBoy


1 Answers

If rebase has not finished, just abort it. If rebase gets stopped due to conflicts, a prompt to resolve them appear. If you cancel the merge prompt without solving the conflict, a notification should appear with options to Resolve conflicts, Continue, and Abort Rebase notification

In addition, with ongoing rebase, the action to Abort rebase is available at the top of the Branches popup

Branches popup

It is also available in VCS - Git menu. You could always use Find action (Ctrl+Shift+A) or Search everywhere (Double shift) to find it. Or use git rebase --abort in the command line, e.g. via builtin Terminal (Alt+F12 to open it)

If rebase has already finished, you should reset the current branch (which is still master) to the commit it used to be on. You could reset it to the same commit where origin/master sits unless there were unpushed commits.

If there were unpushed commits, you have to use git reflog on the command line to find out the hash of the commit, and then reset the current branch there.

thinking that this would have added the changes from master on top of feature branch, unfortunately it happened the opposite

BTW, IntelliJ shows hints clarifying the actions. When you select an action in the branches popup, the status bar shows the description of the action with exact branches names.

like image 174
Dmitriy Smirnov Avatar answered Aug 30 '26 06:08

Dmitriy Smirnov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!