6

From master, the A branch was branched. Then, a few commits (to master) later, B branch was branched.

The owner of A made changes to file fname. The owner of B removed fname altogether.

Then, B was rebased and merged into master. Now, A is to be rebased and merged. But now A's owner gets a conflict with file fname, saying that:

CONFLICT (modify/delete): fname deleted in HEAD and modified in "commit msg". Version "commit msg" of fname left in tree.

Normally, conflicts are resolved by editing the intermediate file, git add fname it and then git rebase --continue the process.

But how to resolve a conflict of a removed file? The end result should be that the files is removed.

ysap
  • 7,723
  • 7
  • 59
  • 122
  • Did you try this: https://stackoverflow.com/questions/5516391/git-rebase-will-not-continue-after-a-delete-modify-conflict – wcarhart Sep 03 '19 at 18:33
  • @wcarhart - Thanks. If I understand correctly, then the recommendation is to `git rm fname` then `git add -A`. But isn't `add -A` and all-inclusive command? What if I have multiple conflicts (some of then are of the nature described in the question, some not), and I want to resolve them one-by-one? Or, if I have untracked files in the repo directory? – ysap Sep 03 '19 at 18:43
  • `-A` will be all inclusive, but you can do `git rm fname` and then `git add ` individually for each change you want to keep. Does that work? – wcarhart Sep 03 '19 at 18:45
  • @wcarhart - unfortunately, not. This was the 1st thing I tried. Got an error: `fatal: pathspec 'fname' did not match any files` – ysap Sep 03 '19 at 18:48
  • Hmm, maybe take a look at this? https://stackoverflow.com/questions/25458306/git-rm-fatal-pathspec-did-not-match-any-files/25458504 – wcarhart Sep 03 '19 at 18:49
  • @wcarhart - don't think so. The question describes a different situation and the answers resolve a different problem. – ysap Sep 03 '19 at 18:54

1 Answers1

2

In this case you can just delete the file not with git rm but just with rm.

rm fname
git add fname
#Fix any other conflict
git rebase --continue

Whichever way you leave your file it will be used in the new commit that is being generated.


What's going on:

  1. The rebase was interrupted because of a conflict.
  2. If you check the log, your current HEAD is the head of master.
  3. You have a file that does not exist in this HEAD. That means that you can't ask git rm because that file is not under version control.
  4. We just remove the file as if you would do with a new file that you don't want to commit.

If the only change in the current commit was on this deleted file you'll get this error:

`No changes - did you forget to use 'git add'?`

This is because there is nothing to commit (You have just deleted a file that did not exist in git) In that case you can git rebase --skip instead of --continue.

Federico Nafria
  • 1,397
  • 14
  • 39