git 如何在 SourceTree 中使用 VS Code 作为合并和差异工具?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49982137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use VS Code as merge and diff tool in SourceTree?
提问by HeyHeyJC
This questionand some others discuss how this could work on a Mac, but I couldn't find documentation from Microsoft or Atlassian on a way to do this on Windows withouttrying to make it the global Git setting. (I just prefer to change things within the IDE where possible.)
这个问题和其他一些人讨论了这如何在 Mac 上工作,但我找不到来自 Microsoft 或 Atlassian 的文档,说明如何在不尝试将其设为全局 Git 设置的情况下在 Windows 上执行此操作。(我只是更喜欢在可能的情况下在 IDE 中更改内容。)
What are the parameters to use with the "Custom" settings in SourceTree's "Options" dialogue "Diff" tab, for diff'ing and merging with VS-Code?
与 SourceTree 的“选项”对话框“差异”选项卡中的“自定义”设置一起使用的参数是什么,用于与 VS-Code 进行比较和合并?
回答by HeyHeyJC
There may be other better variations, but after some experiment I've found these work well enough...
可能还有其他更好的变体,但经过一些实验后,我发现这些变体效果很好......
- Choose "Custom" for the "External Diff Tool" and "Merge Tool"
- The "Diff Command" in both cases is the path to wherever VS-Code is installed, eg:
C:\Program Files (x86)\Microsoft VS Code\Code.exe
The command-line arguments for Diff'ing are:
--diff --wait "$LOCAL" "$REMOTE"
And for Merging:
-n --wait "$MERGED"
- 为“外部差异工具”和“合并工具”选择“自定义”
- 两种情况下的“Diff 命令”都是 VS-Code 安装位置的路径,例如:
C:\Program Files (x86)\Microsoft VS Code\Code.exe
Diff'ing 的命令行参数是:
--diff --wait "$LOCAL" "$REMOTE"
对于合并:
-n --wait "$MERGED"
The '-n' flag makes VS-Code open a new window, which I prefer since VS-Code opens so fast, but you can omit it. When dealing with merge conflicts, you have to close the file when you're done to continue. SourceTree doesn't seem to consistently delete the intermediate files it creates, but you can select, right-click and 'Remove' them from the un-staged file section easily enough.
'-n' 标志使 VS-Code 打开一个新窗口,我更喜欢它,因为 VS-Code 打开速度如此之快,但您可以省略它。处理合并冲突时,您必须在完成后关闭文件才能继续。SourceTree 似乎不会始终删除它创建的中间文件,但您可以轻松地从未暂存的文件部分中选择、右键单击并“删除”它们。
回答by Dan Gardner
I was able to set up with the following steps using the code.cmd
script:
我能够使用code.cmd
脚本通过以下步骤进行设置:
- Setting "Custom" as the external tool for both diff and merge
- Pointing to the
code.cmd
commandC:\Users\[username]\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd
Using the same command-line arguments as @HeyHeyJC explains
The command-line arguments for Diff'ing are:
--diff --wait "$LOCAL" "$REMOTE"
And for Merging:
-n --wait "$MERGED"
- 将“自定义”设置为差异和合并的外部工具
- 指向
code.cmd
命令C:\Users\[用户名]\AppData\Local\Programs\Microsoft VS Code\bin\code.cmd
使用与@HeyHeyJC 解释的相同的命令行参数
Diff'ing 的命令行参数是:
--diff --wait "$LOCAL" "$REMOTE"
对于合并:
-n --wait "$MERGED"
For me I was then able to use both diff and merge from Sourcetree.
对我来说,我可以同时使用 Sourcetree 的 diff 和 merge。
Note: By default thecode.cmd
file contained a command line argument to open the CLIinstructions"%~dp0..\resources\app\out\cli.js"
, and having this open each time was a bit tedious! I removed this so my file looked as follows, and now only the files sent from Sourcetree are opened.
注意:默认情况下,该code.cmd
文件包含一个命令行参数来打开CLI指令"%~dp0..\resources\app\out\cli.js"
,每次都打开它有点乏味!我删除了它,所以我的文件如下所示,现在只有从 Sourcetree 发送的文件被打开。
@echo off
setlocal
set VSCODE_DEV=
set ELECTRON_RUN_AS_NODE=1
call "%~dp0..\Code.exe" %*
endlocal