How to fix CONFLICT (modify/delete): file.txt deleted in branch and modified in HEAD in Git
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.
Quick fix
Fixes CONFLICT (modify/delete): file.txt deleted in branch and modified in HEAD
git status- Check the conflict status
- Review the modifications
- Option A: Keep the modified file
- Option B: Accept the deletion
git statusCONFLICT (modify/delete): file.txt deleted in branch and modified in HEAD
What this error means
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.
Typical symptoms
- Merge or rebase operation stops with CONFLICT (modify/delete) message
- git status shows the file under "Unmerged paths" with "deleted by them" or "deleted by us"
- The file appears in your working directory but Git does not know what to do with it
- Running git merge --continue or git commit fails until conflict is resolved
- Pull requests or merge requests show merge conflicts that cannot be auto-resolved
Common causes
- One branch deleted a file while another branch modified it
- A file was renamed or moved in one branch and edited in another
- A refactoring effort removed files that were still being worked on in feature branches
- A file was moved to a different repository or split into multiple files
- Lack of communication between team members about file reorganization
How to fix "CONFLICT (modify/delete): file.txt deleted in branch and modified in HEAD"
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').
Advanced notes
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 --abortFrequently asked questions
- What does "CONFLICT (modify/delete): file.txt deleted in branch and modified in H" mean?
- 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.
- How do I fix "CONFLICT (modify/delete): file.txt deleted in branch and modified in H"?
- 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.
- What causes "CONFLICT (modify/delete): file.txt deleted in branch and modified in H"?
- One branch deleted a file while another branch modified it A file was renamed or moved in one branch and edited in another A refactoring effort removed files that were still being worked on in feature branches
- Is the "CONFLICT (modify/delete): file.txt deleted in branch and modified in H" error serious?
- It is a low-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Git Official Documentation
- ๐ฌStack Overflow: how to resolve a git conflict modify delete(Stack Overflow)
- ๐
- ๐