我正在使用git rebase -i
来重写历史记录 - 在这种情况下,对早期提交的更改集进行小的更改。换句话说,
A---B---C master
--->
A---B'--C master
我知道C
也在隐式改变,但你明白了。到目前为止,这是我的进展:
git rebase -i HEAD~2
B
从keep
更改为edit
。git commit -a --amend
git rebase --continue
我已经解决了C
中存在冲突的行,但我不确定如何将其标记为已解决,以便可以继续使用rebase。 git commit --amend
尝试修改B
,而git rebase --continue
则抱怨工作树很脏。 (当然,git status
将文件显示为“已修改”。)
我需要做些什么才能让这个rebase回到正轨?
答案 0 :(得分:10)
当您遇到冲突时,您应该会看到如下消息:
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'
这正是你需要做的事情:
# resolve the conflicts somehow
git add <conflicted-file>
git rebase --continue
请勿尝试使用commit --amend
。 HEAD
(当前提交)仍然引用之前的那个,因为冲突阻止了这个提交,正如你所看到的那样,只是修改了已经应用的提交。 rebase --continue
将继续进行包含已解决冲突的新提交。
答案 1 :(得分:1)
您是否已尝试明确地执行此操作,即:git add B'
,然后将其与--amend
一起提交,然后执行git rebase --continue
?