Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interrupt git rebase?

Tags:

git

git-rebase

For example, if I am on feature branch now, I want to rebase it to master branch, so I run the following command.

git rebase master

As I have known, git will switch to branch master, find merge base of feature and master branch, and apply patches of feature branch to master branch one by one.

Now I encounter a conflict, I run git difftool to solve conflict. When solving conflict, I edit my source code to the merged status and I do not want the sequential patches. How can I finish git rebase now?

like image 815
gzh Avatar asked Sep 05 '26 14:09

gzh


1 Answers

If you want to stop rebase in the middle, you should do the following.

  1. After you've resolved all conflicting points, you should add the changes to index with git add, and create a new commit with git commit.
  2. But this comming will be dangling one, so you need to mark it somehow. The easiest way is to git tag it with a temporary tag, but also you can simply remember it's SHA-1.
  3. Then you should use git rebase --abort to return your branch to the state it was before the rebase
  4. Now you can forcibly set the branch to the commit you've created during the merge with git reset --hard <tag_name_or_remembered_SHA1>.

In any case you can revert the changes with git reset --hard. You can check the output of git reflog to see the whole list of recent actions including rebase, resets and new commits.

like image 141
user3159253 Avatar answered Sep 08 '26 03:09

user3159253



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!