Files
smartDriveEEUniApp/git-merge-helper.md
2026-01-03 20:58:40 +08:00

1.5 KiB
Raw Permalink Blame History

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 ""

推荐操作流程

对于你当前的情况,建议按顺序尝试:

  1. 首先尝试自动合并(无冲突):

    git pull --no-edit
    
  2. 如果有冲突,全部接受远程版本:

    git checkout --theirs .
    git add .
    git commit --no-edit
    
  3. 如果遇到合并消息编辑界面,直接关闭保存即可(使用默认消息)