1.5 KiB
1.5 KiB
Git 批量合并操作指南
情况 1:需要自动接受所有远程更改(推荐)
如果你想接受远程分支的所有更改:
# 先中断当前合并(如果还在合并状态)
git merge --abort
# 然后使用策略自动接受远程版本
git pull --no-edit -X theirs
情况 2:需要自动接受所有本地更改
如果你想保留本地版本:
git merge --abort
git pull --no-edit -X ours
情况 3:自动完成合并(无冲突时)
如果只是需要自动使用默认合并消息,不需要编辑:
git pull --no-edit
情况 4:已有冲突,需要批量解决
如果已经进入合并状态,有多个冲突文件:
方法 A:全部接受远程版本
git checkout --theirs .
git add .
git commit --no-edit
方法 B:全部接受本地版本
git checkout --ours .
git add .
git commit --no-edit
配置 Git 默认编辑器避免弹出编辑器
如果你想以后自动使用默认合并消息,可以设置:
git config --global core.editor "true"
或者设置为空字符串:
git config --global core.editor ""
推荐操作流程
对于你当前的情况,建议按顺序尝试:
-
首先尝试自动合并(无冲突):
git pull --no-edit -
如果有冲突,全部接受远程版本:
git checkout --theirs . git add . git commit --no-edit -
如果遇到合并消息编辑界面,直接关闭保存即可(使用默认消息)