This Git merge conflict occurs when a file was deleted in one branch but modified in your current branch (HEAD). Git cannot automatically decide whether to keep your changes or accept the deletion, requiring manual resolution.
When Git displays 'CONFLICT (modify/delete)', it means you are attempting to merge two branches with incompatible changes to the same file. In your current branch (HEAD), the file was edited and contains modifications. In the branch you're merging from, the same file was deleted entirely. Git cannot automatically resolve this because it doesn't know your intent. Should it keep your modified version of the file, or should it accept the deletion from the other branch? This is a decision only you can make, because it requires understanding why the file was deleted and whether your changes are still relevant. This type of conflict is common in team environments where one developer removes a file (perhaps as part of a refactor) while another developer continues to work on it. It can also happen when files are renamed or moved to a different location, as Git sometimes interprets a rename as a delete-and-create operation.
Run git status to see which files are in conflict and understand the situation:
git statusLook for files listed under 'Unmerged paths'. The output will indicate whether the file was 'deleted by them' (deleted in the branch you're merging) or 'deleted by us' (deleted in your current branch).
Before deciding whether to keep or delete the file, review what changes were made. You can see the modifications using:
git diff HEAD -- path/to/file.txtOr to see the file's history and understand why it might have been deleted:
git log --oneline -- path/to/file.txtIf you want to keep your modifications and restore the file, stage it with git add:
git add path/to/file.txtThis tells Git to include the file in the merge result with your modifications intact.
If the file should be deleted (perhaps the modifications are no longer needed), remove it with git rm:
git rm path/to/file.txtThis tells Git to accept the deletion and not include the file in the merge result.
After resolving all conflicts, complete the merge by committing:
git commitOr if you're in the middle of a merge:
git merge --continueGit will open your editor for a commit message. The default merge commit message usually works fine.
For a more interactive approach, you can use git mergetool:
git mergetoolThis will prompt you for each conflicted file. For modify/delete conflicts, it will ask whether you want to keep the modified version (press 'm') or delete the file (press 'd').
When a file is renamed or moved in one branch and modified in another, Git may report this as a modify/delete conflict because it doesn't always detect renames perfectly. In these cases, you may need to manually apply your modifications to the file at its new location.
To check if a file was renamed rather than deleted, look at the commit that removed it:
git log --diff-filter=D --summary | grep -A 5 'file.txt'
git log --diff-filter=R --summary # Shows renamesIf you frequently encounter modify/delete conflicts, consider these preventive measures:
1. Pull frequently: Regular pulls from the main branch help catch file reorganizations early
2. Communicate refactoring: When renaming or deleting files, notify team members who might be working on them
3. Use feature flags: Instead of deleting code, consider using feature flags to disable it temporarily
4. Smaller, focused branches: Keep feature branches small and merge them quickly to reduce divergence
If you need to abort the merge and start over:
git merge --abortwarning: BOM detected in file, this may cause issues
UTF-8 Byte Order Mark (BOM) detected in file
fatal: Server does not support --shallow-exclude
Server does not support --shallow-exclude
warning: filtering out blobs larger than limit
Git partial clone filtering large blobs warning
fatal: Server does not support --shallow-since
Server does not support --shallow-since in Git
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server