Unmerged Files
错误信息
错误: 提交是不可能因为你有 unmerged files
快速摘要
合并 or rebase 是 in progress 使用 unresolved conflicts — 你必须 resolve 它们之前 committing.
为什么发生
合并 conflict 是不 fully resolved 之前 committing
你 staged 一些但不所有 conflicted files
rebase paused on conflicts and 你有不 finished resolving
最小示例
✗ 错误代码
git commit -m "Merge" # error: you have unmerged files✓ 修复代码
# Resolve conflicts in the file
# Edit file to remove <<<<<<<, =======, >>>>>>> markers
git add conflicted-file.txt
git commit -m "Merge: resolve conflict"你必须 resolve 所有 conflicts (移除 markers, 选择正确 version) and git 添加每个 file 之前 committing.
如何诊断
运行 git 状态到 see 哪个 files still 有 conflicts
打开 conflicted files and look for <<<<<<<, =======, >>>>>>> markers
运行 git diff 到 see unresolved conflict details
如何修复
编辑每个 conflicted file 到选择正确 version and 移除 markers
运行 git 添加 <file> for 每个 resolved file
运行 git 提交到完整合并, or git rebase --continue for rebase
到 abort: git 合并 --abort or git rebase --abort
如何预防
总是 resolve 所有 conflicts 之前 committing
Use git 状态到验证否 files 有 conflicts 之前 committing