Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I continue merging after a double-modify?

I'm using git rebase -i to rewrite history — in this case, make a small alteration to an earlier commit's change set. In other words,

A---B---C master

      --->

A---B'--C master

I know C is implicitly changing, too, but you get the idea. Here's my progress so far:

  1. git rebase -i HEAD~2
  2. Change B from keep to edit.
  3. Edit the file.
  4. git commit -a --amend
  5. git rebase --continue
  6. "Could not apply [C]..."

I've resolved the conflicted lines in C, but am unsure how to mark it as resolved so that the rebase can continue. git commit --amend attempts to amend B, while git rebase --continue complains that the working tree is dirty. (And, sure enough, git status shows the file as "both modified".)

What do I need to do to get this rebase back on track?

like image 405
Ben Blank Avatar asked Apr 17 '11 23:04

Ben Blank


2 Answers

When you run into the conflicts, you should see a message something like this:

error: could not apply 45cb26a... <commit message subject>
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' and run 'git rebase --continue'

And that's exactly what you need to do:

# resolve the conflicts somehow
git add <conflicted-file>
git rebase --continue

Don't try to use commit --amend. HEAD (the current commit) still refers to the one just before, since the conflicts have prevented this commit from being made, so as you saw, that just amends the already-applied commit. rebase --continue will proceed to make the new commit containing the resolved conflicts.

like image 121
Cascabel Avatar answered Sep 21 '22 14:09

Cascabel


Have you tried doing it explicitly, i.e.: git add B', then committing it with --amend, then doing git rebase --continue?

like image 37
urschrei Avatar answered Sep 19 '22 14:09

urschrei