Git: how to fix commit during rebase

I ran into the following problem:

During git rebase, one of the automatically resolved commits has an error, that is, as a result of automatic resolution, the function declaration was entered into the header file a second time, and compilation failed.

My question is: can I go back to this automatically resolved commit, manually resolve it, and then continue with rebase, assuming I'm still in the forwarding process?

+4
source share
2 answers

You must first complete the initial rebase so that you are in a known state with your repository. Then it’s pretty easy to edit the commit that introduced the interactive permutation error. Check the sha1 commit you want to fix, then do

git rebase -i <sha1>^ 

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

Now you can fix the error, then do

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

What is it!

+6
source

Although git commit --amend will not work, it is possible to execute git commit --amend before the last committed modification.
If the problem is caused by a commit just before the current one was rebased (i.e., it was last fixed), you can change it without any side effects during rebasing.

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

  1. Cancel the current modification manually:

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

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

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

     $ git add <files being rebased> 

Hope this helps.

0
source

All Articles