0%

设置git mergetool为vscode

Window环境:

在git bash中设置如下config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 编辑器 这个可以不改..修改之后git所有编辑器都会调用vscode
git config --global core.editor 'code --wait'

# merge工具
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait $MERGED'
git config --global mergetool.vscode.trustExitCode true

# diff工具
git config --global diff.tool vscode
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'

# 关闭*.orig备份文件生成
git config --global mergetool.keepBackup false

Eg.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 初始分支状态
# master:
# 新建文本文档.txt : aaaaa123(asdasf1)
# dev:
# 新建文本文档.txt : aa123(121245123412assdasd)

git checkout master
git merge dev
# 显示auto-merge failed:
# Auto-merging 新建文本文档.txt
# CONFLICT (content): Merge conflict in 新建文本文档.txt
# Automatic merge failed; fix conflicts and then commit the result.
git mergetool
# Merging:
# 新建文本文档.txt
#
# Normal merge conflict for '新建文本文档.txt':
# {local}: modified file
# {remote}: modified file

# 弹出vscode窗口,merge当前文件

image-20220319183813584

image-20220319183839389
1
2
3
# 选择merge来源后保存关闭窗口,git mergetool打开下一个需要merge的文件,当没有下一个文件时退出工作流
git commit
# 自动生成Merge提交记录