今天我试图在Windows命令提示符上使用git mergetool
,并意识到默认使用VIM,这很酷,但我更喜欢VSCode。
如何将Visual Studio代码功能作为我的GUI来处理Git的合并冲突(甚至作为差异化工具)?
从VSCode 1.13开始,Better Merge被整合到VSCode的核心中。
将它们连接在一起的方法是修改你的.gitconfig
,你有两个选择。
"
替换'
)
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd "code --wait $MERGED"
git config --global diff.tool vscode
git config --global difftool.vscode.cmd "code --wait --diff $LOCAL $REMOTE"
.gitconfig
with VS Code中粘贴一些线来做到这一点。
从命令行运行git config --global core.editor "code --wait"
。
从这里你可以输入命令git config --global -e
。您需要粘贴下面“额外块”中的代码。
[user]
name = EricDJohnson
email = [email protected]
[gui]
recentrepo = E:/src/gitlab/App-Custom/Some-App
# Comment: You just added this via 'git config --global core.editor "code --wait"'
[core]
editor = code --wait
# Comment: Start of "Extra Block"
# Comment: This is to unlock VSCode as your git diff and git merge tool
[merge]
tool = vscode
[mergetool "vscode"]
cmd = code --wait $MERGED
[diff]
tool = vscode
[difftool "vscode"]
cmd = code --wait --diff $LOCAL $REMOTE
# Comment: End of "Extra Block"
现在来自你的git目录中的冲突运行git mergetool
和tada,你有VSCode帮助你处理合并冲突! (只需确保在关闭VSCode之前保存文件)。
有关从命令行启动code
的进一步阅读,请查看这些docs。
有关git mergetool
的更多信息,请查看这些docs。
我不得不用简单的引号替换双引号:
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'
为了它正常工作。 (使用双引号,$ LOCAL和$ REMOTE将被其值替换)
如果您使用Git Bash for Windows而不是Windows命令提示符,则需要这样做。