合并 Conflict
快速摘要
Git 停止 mid-合并因为两者都分支编辑相同行 — 你必须 manually 选择哪个 version 到 keep.
为什么发生
两者都分支修改相同行的相同 file
One 分支删除 file 虽然 other 修改它
Conflicting 更改是制作到 overlapping 区域
最小示例
✗ 错误代码
<<<<<<< HEAD
const port = 3000;
=======
const port = 8080;
>>>>>>> feature-branch✓ 修复代码
const port = 8080; // resolved: use the feature branch's value两者都分支设置 port 到不同值 — 选择正确 one (8080), 移除 conflict markers, and 提交.
如何诊断
运行
git 状态到 see 哪个 files 有 conflicts打开 conflicted files and look for
<<<<<<<,=======, and>>>>>>>markersReview 两者都 versions 到理解什么每个分支更改
如何修复
编辑每个 conflicted file 到 keep 正确 version and 移除 markers
运行
git 添加 <file>到 mark conflict as resolved运行
git 提交(orgit 合并 --continue) 到完整合并
如何预防
拉取从 remote 频繁地到 keep 你的分支上到 date
Keep feature 分支短 and 合并它们快速地
Communicate 使用你的 team 到 avoid 编辑相同 files simultaneously