git rebase
does not appear to work properly in certain cases where a file is added to the repository, then removed from the repository, then added to the working directory (but not the repository).
Here's a more specific description of my problem:
if a branch is created and switched to from some trunk,
and a file X is added and committed in the branch,
and subsequently X is removed and committed in the branch,
and X is again created in the working directory, but not added or committed,
and the trunk branch advances,
then
a rebase performed using the advanced trunk as the base will fail because it will refuse to overwrite X,
and the rebase cannot be continued even if the working directory X is removed or moved out of the way.
Here's a script to reproduce my problem on the command line:
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".
I know I can abort the rebase using git rebase --abort
, remove bar.txt
, and then git rebase master
again. But how can I continue the rebase without aborting it first?