Rebasing with unwanted untracked files. Error merging

Multi tool use


Rebasing with unwanted untracked files. Error merging
I've come across this problem a few times and I have not been able to find an answer yet. Apologies if it turns out to be a duplicate.
Suppose I have the three following commits:
A -- B -- C
(In each commit new files were added).
At some point I want to edit commit A, so I rebase -i
and mark A for edit. Unfortunately, I use Sublime as my editor and I mistakenly save one of the files that were committed in C (say file.cpp) while I am editing A. Upon doing git status
now there is an untracked file, as expected.
rebase -i
git status
Now once I have made the edits to A that I wanted, I forget about the untracked file and I do git rebase --continue
. Upon reaching commit C, I get the error
git rebase --continue
error: The following untracked working tree files would be overwritten by merge:
file.cpp
What should I do at this point? I've tried git stash
followed by git rebase --continue
, but now I end up with A -- B commits instead of A -- B -- C.
git stash
git rebase --continue
Thanks.
git status
1 Answer
1
Upon finding such a file, you're left before the new commit is applied. git stash
does nothing, because the only thing left is that untracked file.
git stash
You can then git add file.cpp
, git stash
, git rebase --continue
, git stash pop
and all will be fine. Just tested with 2.18.
git add file.cpp
git stash
git rebase --continue
git stash pop
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
If you run
git status
at that point, the output should include what Git commands you can run to accept either version of the file.– Rory O'Kane
yesterday