问题
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:
git rebase -i HEAD~2
- Change
B
fromkeep
toedit
. - Edit the file.
git commit -a --amend
git rebase --continue
- "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?
回答1:
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.
回答2:
Have you tried doing it explicitly, i.e.: git add B'
, then committing it with --amend
, then doing git rebase --continue
?
来源:https://stackoverflow.com/questions/5697184/how-can-i-continue-merging-after-a-double-modify