How to use Visual Studio Code as the default editor for Git MergeTool

后端 未结 5 2135
失恋的感觉
失恋的感觉 2020-12-12 09:18

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 prefe

5条回答
  •  渐次进展
    2020-12-12 09:49

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

    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: (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"
    2. To do this by pasting some line in the .gitconfig with Visual Studio 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"'
        [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"
        

    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.)

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

    For more information in git mergetool check out this documentation.

提交回复
热议问题