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

82 lines
1.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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