Git Merge Conflicts Although the File Does Not Exist

I had a similar issue after renaming a file and trying a rebase. I got the message:

"com.mycompany.fileThatDoesNotExist.java needs merge. You must edit all merge conflicts and then mark them as resolved using git add".

I solved it by removing the file with the command:

git rm com.mycompany.fileThatDoesNotExist.java

I resolved this issue by running git reset.


In my case I had this same issue because of the fact that file-renames in git are a run-time heuristic. (This is what Michael Monteith's answer proposes, but without a solution.)

git, at merge time, decided that the non-existing file in my branch was actually a rename of a file with similar contents that does exist on my branch. Any files with 50% similarity in a single commit are considered a rename during the merge, by default. Asking git to merge with a higher threshold does the trick:

git merge {branch} -X rename-threshold=100%

As to why I hit this issue: it's because our team decided on a single-squash-commit strategy for pull-requests. That means that individual commits on master are huge, thus multiplying the chance for "renames" (i.e., similar files at different paths) within those single, massive commits.


It could be that the modified file in your feature branch has been renamed in the develop branch?

I had a problem where master had renamed a file for example A.java to B.java, and the feature branch had made changes to A.java.
I had merge conflicts with B.java even though the feature branch had no history of a file called B.java

Tags:

Git

Merge