如何将Visual Studio代码用作Git MergeTool的默认编辑器 [英] How to use Visual Studio Code as Default Editor for Git MergeTool

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

问题描述

今天,我试图在Windows命令提示符下使用 git mergetool ,并意识到使用 VIM 但我更喜欢 VSCode



如何将 Visual Studio Code 函数作为我的GUI来处理Git的合并冲突(甚至是差异化工具)?



有关从命令行启动 code 的进一步阅读,请查看这些 docs

有关 git mergetool 中的更多信息,请查看这些 docs


Today I was trying to use the git mergetool on Windows Command Prompt and realized that it was defaulting to use VIM, which is cool, but I'd prefer VSCode.

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

解决方案

As of VSCode 1.13 Better Merge was integrated into the core of VSCode.

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

  1. To do this with command line entries, enter each of these:

    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"

  2. To do this by pasting some line in the .gitconfig with VS Code.

    • 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"'
      [code]
          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"
      

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

For further reading on launching code from the command line look in these docs.

For more info in git mergetool check out these docs.

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

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