During a git rebase origin/main I ran into a merge conflict. A file did not exists in the local branch but in the main branch.
I then ran git mergetool and it asked me what I want to do:
Merging:
src/CMakeLists.txt
Deleted merge conflict for 'src/CMakeLists.txt':
{local}: created file
{remote}: deleted
Use (c)reated or (d)eleted file, or (a)bort? d
I selected (d)eleted file, which was wrong. After I continued the rebase I found that the file was missing.
I then checkout out the missing file using git checkout origin/main src/CMakeLists.txt, so I could recover the file.
However, the commit history now has an unintended additional commit which may lead to problems if further rebases may be necessary.
I would merely like to undo my decision so that the commit history would be the same as if I had selected the correct answer in the first place.
If it is just about keeping the
origin/masterversion ofCMakeLists.txtthrough all your history :git rebase -i origin/masterbreakinstruction right after the first commit, save & exitgit rebasestops, rungit rebase --continuegit checkout origin/master -- src/CMakeLists.txtto restore that versiongit rebasestopping because there are no changes left for a particular commit, in that case rungit rebase --skipto skip replaying that commitIf, on the other hand, you had modifications on that file which you want to preserve and restore :
git reflogorgit reflog my/working/branchgit rebasegit reset --hard <sha>git rebase origin/masteragainA generic warning on
git reset --hard:run it on a clean worktree, it is one of the very few commands in git that can remove some files or modifications from your disk without them being stored in git.