8

I came across the following problem:

During git rebase one of automatically resolved commits has an error, i.e. as a result of automatic resolution, a function declaration was introduced for the second time in the header file and compilation fails.

My question is: is it possible to go back to that automatically resolved commit, resolve it manually and then continue with the rebase, assuming that I am still within the rebase process?

2 Answers 2

10

You should first finish the original rebase, so that you are in a known state with your repository. Then it is quite easy to edit the commit that introduced the error with interactive rebase. Check out the sha1 of the commit you want to fix, then do

git rebase -i <sha1>^

An editor will open containing commits from the HEAD up to the commit you want to fix. Find the commit from the list (it should be the first one), replace the word "pick" with "edit", save and exit editor.

Now you can fix the bug, then do

git commit -a --amend
git rebase --continue

That's it!

4
  • Thank you very much for help! Do you know if it is possible to fix the commit while I am rebasing? The problem that I have is that my rebase is very large and I would like to check if the code compiles after each manually resolved commit. I tried to do git reset --soft HEAD^, but I think that after git rebase --continue the commit got skipped (it's not showing in the history).
    – Tomek
    Jan 12, 2013 at 16:42
  • I don't think you can start an interactive rebase nested with the original rebase. However you can make modifications anywhere you want and include them in each manually resolved commit. Jan 12, 2013 at 17:09
  • Thanks again! Yes, you are right - rebase -i will not start if I am during another rebase operation. Since I did not continued with the rebase after the "wrong" commit I was wondering of doing the following: 1. git stash (to save currently resolved changes) 2. edit the file that was resolved incorrectly 3. git add <file> 4. git commit --amend 5. git stash pop Do you think that this correct while being "inside" rebase process? I guess that git commit --amend will change the SHA checksum of edited commit.
    – Tomek
    Jan 12, 2013 at 17:28
  • I'm sorry - I just realised, that I may apply the fix in the current manually resolved commit and then use the suggested git rebase -i to apply the change to the right place after my current rebase is finished. Your really helped me a lot - Thanks!
    – Tomek
    Jan 12, 2013 at 17:37
1

Although a rebase within a rebase will not work, it is possible to git commit --amend to the last committed modification.
If the problem is caused by the commit just before the current one being rebased (i.e its the last one committed), you can modify it without any side effects to the rebase process.

So when I got into this situation, I did the following:

  1. Unstage the current manual modification being rebased:

    $ git reset HEAD <files being rebased>
    
  2. Stage my fix for the last commit causing the problem:

    $ git add <files with compilation fix>
    
  3. Add the compilation fix into the last committed modification:

    $ git commit --amend
    
  4. Return to the current manual modification being rebased:

    $ git add <files being rebased>
    

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.