如何使用Visual Studio Code作为Git MergeTool的默认编辑器 [英] How to use Visual Studio Code as the default editor for Git MergeTool

查看:362
本文介绍了如何使用Visual Studio Code作为Git MergeTool的默认编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我试图在Windows命令提示符下使用git mergetool,并意识到它默认使用 Vim ,这很酷,但是我更喜欢 VS Code .

Today I was trying to use the git mergetool on the Windows command prompt and realized that it was defaulting to use Vim, which is cool, but I'd prefer VS Code.

如何让 Visual Studio Code 作为我的GUI处理Git的合并冲突(或什至作为差异工具)?

How can I have Visual Studio Code function as my GUI for handling merge conflicts (or even as a diffing tool) for Git?

推荐答案

截至 Visual Studio Code 1.13 更好的合并已集成到Visual Studio Code的核心中.

As of Visual Studio Code 1.13 Better Merge was integrated into the core of Visual Studio Code.

将它们连接在一起的方法是修改您的.gitconfig,您有两个选项.

The way to wire them together is to modify your .gitconfig and you have two options.

  1. 要使用命令行条目执行此操作,请输入以下各项:(注意:如Iztok Delfin和e4rache所述,在Windows Git Bash,macOS和Linux上将"替换为')

  1. To do this with command line entries, enter each of these: (Note: replace " with ' on Windows Git Bash, macOS and Linux as clarified by Iztok Delfin and e4rache)

  1. git config --global merge.tool vscode
  2. git config --global mergetool.vscode.cmd "code --wait $MERGED"
  3. git config --global diff.tool vscode
  4. git config --global difftool.vscode.cmd "code --wait --diff $LOCAL $REMOTE"
  1. git config --global merge.tool vscode
  2. git config --global mergetool.vscode.cmd "code --wait $MERGED"
  3. git config --global diff.tool vscode
  4. git config --global difftool.vscode.cmd "code --wait --diff $LOCAL $REMOTE"

  • 通过在.gitconfig 使用Visual Studio代码.

    • 从命令行运行git config --global core.editor "code --wait".
    • 在这里您可以输入命令git config --global -e.您将需要在下面的额外块"中粘贴代码.

    • Run git config --global core.editor "code --wait" from the command line.
    • From here you can enter the command git config --global -e. You will want to paste in the code in the "Extra Block" below.

    [user]
        name = EricDJohnson
        email = cool-email@neat.org
    [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 Visual Studio Code 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,Visual Studio Code可帮助您处理合并冲突! (只需确保在关闭Visual Studio代码之前先保存文件.)

    Now from within your Git directory with a conflict run git mergetool and, tada, you have Visual Studio Code helping you handle the merge conflict! (Just make sure to save your file before closing Visual Studio Code.)

    有关从命令行启动code的更多信息,请参见此文档.

    For further reading on launching code from the command line, look in this documentation.

    有关git mergetool中的更多信息,请查看此文档.

    For more information in git mergetool check out this documentation.

    这篇关于如何使用Visual Studio Code作为Git MergeTool的默认编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆