git conflict_error ai_generated true

CONFLICT (modify/delete): file.txt deleted in HEAD and modified in branch. Version branch of file.txt left in tree.

ID: git/conflict-modify-delete

Also available as: JSON · Markdown · 中文
85%Fix Rate
85%Confidence
1Evidence
2023-06-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
git 2.30.0 active
git 2.39.0 active
git 2.45.0 active

Root Cause

One side of a merge deleted a file while the other side modified it, causing a modify/delete conflict.

generic

中文

合并的一方删除了一个文件,而另一方修改了该文件,导致修改/删除冲突。

Official Documentation

https://git-scm.com/docs/git-merge#_how_to_resolve_conflicts

Workarounds

  1. 80% success git checkout --ours file.txt && git add file.txt # Keep the deleted side (HEAD), effectively deleting the file
    git checkout --ours file.txt && git add file.txt  # Keep the deleted side (HEAD), effectively deleting the file
  2. 85% success git checkout --theirs file.txt && git add file.txt # Keep the modified side (branch), restoring the file with modifications
    git checkout --theirs file.txt && git add file.txt  # Keep the modified side (branch), restoring the file with modifications

中文步骤

  1. git checkout --ours file.txt && git add file.txt  # Keep the deleted side (HEAD), effectively deleting the file
  2. git checkout --theirs file.txt && git add file.txt  # Keep the modified side (branch), restoring the file with modifications

Dead Ends

Common approaches that don't work:

  1. 65% fail

    Running git add on the conflicted file without resolving the conflict will keep the conflict marker in the staged file, leading to build errors or incorrect content.

  2. 30% fail

    Using git merge --abort when you actually want to keep changes discards all merge progress and requires starting over.