我使用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
- "Could not apply [C]…"
我已经解决了C
中的冲突行,但我不确定如何将其标记为已解决,以便rebase可以继续。git commit --amend
试图修改B
,而git rebase --continue
抱怨工作树脏了。(当然,git status
显示文件为"both modified")
我需要做些什么才能让这个基础回到正轨?
当您遇到冲突时,您应该看到类似这样的消息:
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
将继续创建包含解决冲突的新提交。
您是否尝试过明确地执行此操作,即:先执行git add B'
,然后提交--amend
,然后执行git rebase --continue
?