gpt4 book ai didi

git - 如何使用 Visual Studio Code 作为 Git MergeTool 的默认编辑器,包括 3 向 merge

转载 作者:IT王子 更新时间:2023-10-29 01:25:40 28 4
gpt4 key购买 nike

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

如何让 Visual Studio Code 充当我的 GUI 来处理 Git 的 merge 冲突(或者甚至作为差异工具)?

是否可以设置 VS Code 以获得 three-way merge 的视觉效果? ?

最佳答案

更新截至Visual Studio Code 1.70添加了改进的三向 merge Visuals and further explanations如果您对此感兴趣,可以使用 😉。

截至Visual Studio Code 1.13 Better Merge 已集成到Visual Studio Code 的核心。

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

  1. 要使用命令行条目执行此操作,请输入以下各项:(注意:如果在 Windows 命令提示符下将 ' 替换为 "。谢谢感谢 Iztok Delfin 和 e4rache 帮助澄清这一点。)

    1. git config --global merge.tool vscode
    2. git config --global mergetool.vscode.cmd 'code --wait --merge $REMOTE $LOCAL $BASE $MERGED'
    3. git config --global diff.tool vscode
    4. git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'
  2. 通过在 .gitconfig 中粘贴一些行来做到这一点 with Visual Studio Code .

    • 从命令行运行 git config --global core.editor 'code --wait'

    • 从这里您可以输入命令 git config --global -e。您需要将代码粘贴到下面的“额外 block ”中。

        [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"]
      # Comment: Original way before three-way merge shown commented out
      # cmd = code --wait $MERGED
      # Comment: For "Three-way merge"
      cmd = code --wait --merge $REMOTE $LOCAL $BASE $MERGED
      [diff]
      tool = vscode
      [difftool "vscode"]
      cmd = code --wait --diff $LOCAL $REMOTE
      # Comment: End of "Extra Block"

现在,在有冲突的 Git 目录中运行 git mergetool,然后,你有 Visual Studio Code 帮助你处理 merge 冲突! (只需确保在关闭 Visual Studio Code 之前保存文件。)

Accept Incoming Change anyone?

要进一步阅读有关从命令行启动 code 的信息,请查看 this documentation .

有关 git mergetool 的更多信息,请查看 this documentation .

关于git - 如何使用 Visual Studio Code 作为 Git MergeTool 的默认编辑器,包括 3 向 merge ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44549733/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com