git rebase
在将文件添加到存储库,然后从存储库中删除,然后添加到工作目录(但不是存储库)的某些情况下,似乎无法正常工作。
这是对我的问题的更具体的描述:
如果创建了一个分支并从某个主干切换到,
并且在分支中添加并提交了一个文件 X,
随后 X 被删除并提交到分支中,
并且 X 再次在工作目录中创建,但未添加或提交,
和主干分支前进,
然后
使用高级主干作为基础执行的变基将失败,因为它将拒绝覆盖 X,
即使工作目录 X 被移除或移开,也无法继续变基。
这是在命令行上重现我的问题的脚本:
git init
echo foo > foo.txt
git add .
git commit -m 'foo'
echo foo >> foo.txt
git add .
git commit -m 'foo foo'
git checkout -b topic HEAD^
git log
echo bar > bar.txt
echo baz > baz.txt
git add .
git commit -m 'bar baz'
git rm bar.txt
git commit -m '-bar'
echo bar > bar.txt
git rebase master
# the following output is emitted:
# First, rewinding head to replay your work on top of it...
# Applying: bar baz
# Using index info to reconstruct a base tree...
# Falling back to patching base and 3-way merge...
# error: Untracked working tree file 'bar.txt' would be overwritten by merge. Aborting
# Failed to merge in the changes.
# Patch failed at 0001 bar baz
#
# When you have resolved this problem run "git rebase --continue".
rm bar.txt
git rebase --continue
# the following output is emitted:
# Applying: bar baz
# No changes - did you forget to use 'git add'?
#
# When you have resolved this problem run "git rebase --continue".
# If you would prefer to skip this patch, instead run "git rebase --skip".
# To restore the original branch and stop rebasing run "git rebase --abort".
我知道我可以使用git rebase --abort
、removebar.txt
和git rebase master
再次中止 rebase。但是我怎样才能在不先中止它的情况下继续 rebase 呢?