Eri*_*son 100 git cmd mergetool git-merge visual-studio-code
今天我试图使用git mergetoolWindows命令提示符,并意识到它默认使用VIM,这很酷,但我更喜欢VSCode.
如何将Visual Studio代码功能作为我的GUI来处理Git的合并冲突(甚至作为差异化工具)?
Eri*_*son 199
从VSCode 1.13开始, Better Merge被整合到VSCode的核心中.
将它们连接在一起的方法是修改你的.gitconfig,你有两个选择.
要使用命令行输入为此,输入每个这些:(注:替换"与'Windows上的Git的Bash由Iztok海豚和澄清e4rache)
git config --global merge.tool vscodegit config --global mergetool.vscode.cmd "code --wait $MERGED"git config --global diff.tool vscodegit config --global difftool.vscode.cmd "code --wait --diff $LOCAL $REMOTE"要通过在.gitconfig VS代码中粘贴一些行来完成此操作.
git config --global core.editor "code --wait"命令行.从这里您可以输入命令git config --global -e.您需要粘贴下面"额外块"中的代码.
[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 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"
Run Code Online (Sandbox Code Playgroud)现在来自你的git目录中的冲突运行git mergetool和tada,你有VSCode帮助你处理合并冲突!(只需确保在关闭VSCode之前保存文件).
有关code从命令行启动的进一步阅读,请查看这些文档.
有关详细信息,git mergetool请查看这些文档.
小智 18
我不得不用简单的引号替换双引号:
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'
Run Code Online (Sandbox Code Playgroud)
为了它正常工作.
(使用双引号,$ LOCAL和$ REMOTE将被其值替换)
如果您使用Git Bash for Windows而不是Windows命令提示符,则需要这样做.
mvd*_*mvd 17
除了现有的优秀答案之外,您应该通过添加-n到命令行在新窗口中打开 VS Code 。
所以你git config --global --edit看起来像这样。
[merge]
tool = vscode
[mergetool "vscode"]
cmd = code -n --wait $MERGED
[diff]
tool = vscode
[difftool "vscode"]
cmd = code -n --wait --diff $LOCAL $REMOTE
Run Code Online (Sandbox Code Playgroud)
使用手册你可以找到一个有趣的论点:
git difftool --help
-x <command>, --extcmd=<command>
Specify a custom command for viewing diffs. git-difftool ignores the configured defaults and runs $command $LOCAL $REMOTE when this option is specified.
Additionally, $BASE is set in the environment.
Run Code Online (Sandbox Code Playgroud)
有了这些信息,您可以轻松使用以下命令,而无需接触 git 配置:
git difftool -x "code --wait --diff"
Run Code Online (Sandbox Code Playgroud)
类似的问题在这里
| 归档时间: |
|
| 查看次数: |
36641 次 |
| 最近记录: |