Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git - merge conflict when local is deleted but file exists in remote

Tags:

git

People also ask

How do I fix a merge conflict with deleted files?

Select Stage Changed Files To Commit (Ctrl-I) from Commit menu. Enter a commit comment like "deleted conflicting file" Commit (ctrl-enter) Now if you restart the merge it will (hopefully) work.


You should resolve the conflicts as you see fit. If the file really is supposed to be removed, and you will be publishing that change to origin, remove it again:

git rm path/to/file

If the file should in fact be tracked still, add it (the version in the work tree will be the version from origin):

git add path/to/file

After doing either of those to resolve the conflict, commit the merge.


As an added tip in addition to the accepted answer, in a "deleted by us", if you would like to see the changes that were made to the deleted file so that you may apply those changes elsewhere you can use:

git diff ...origin/master -- path/to/file

If it is a "deleted by them" scenario, and you would like to see the changes so you can apply them elsewhere, you can use:

git diff origin/master... -- path/to/file

In Git GUI, you select the conflicted file and then right-click on the main text area where the conflicted text is shown.

In the context menu that appears, you can choose to go with "Remote" or go with "Local". So if a file is remotely deleted, you can choose "Remote" to propagate the delete locally, and vice versa.

Took me a month to figure it out...it would be nice if Git GUI actually had documentation...


The best-rated answer focuses on the way to resolve the conflict.

Before that, you probably want to know what the remote changed in the locally removed files.

To do that, you can see the changes with:

git diff --base

From https://git-scm.com/docs/git-diff#Documentation/git-diff.txt--1--base

Compare the working tree with the "base" version [...]. The index contains these stages only for unmerged entries i.e. while resolving conflicts.