如何使用Visual Studio Code作为Git的默认编辑器 [英] How to use Visual Studio Code as Default Editor for Git
问题描述
在命令行使用git时,我想知道是否可以使用Visual Studio Code作为默认编辑器,即创建提交注释并从命令行查看文件的差异。
据我所知,它不可能用于合并(至少在一分钟内),但是有人知道是否可以使用它来查看diff,如果是这样,在.gitconfig文件中需要哪些命令行选项才能实现此目的?
更新1:
我尝试了一种类似于我为
添加以下内容以支持使用VS Code作为diff工具:
[diff]
工具=默认 - 差异工具
[difftooldefault-difftool]
cmd = code --wait - -diff $ LOC $ $ REMOTE
这利用了新的<$ c $ > b
$ b总结一下,这里总结一下是你可以在VS中使用Git的一些例子:
$ b $ ul
$ git rebase HEAD〜3
git commit
允许使用VS Code进行提交消息
git add -p
后跟e
li>
git difftool< ; commit> ^< commit>
允许使用VS Code作为差异编辑器进行更改
When using git at the command line, I am wondering if it is possible to use Visual Studio Code as the default editor, i.e. when creating commit comments, and looking at a diff of a file from the command line.
I understand that it won't be possible to use it for doing merges (at least at the minute) but does anyone know if it is possible to use it for looking at diff's, and if so, what command line options would be required in the .gitconfig file to make this happen?
UPDATE 1:
I have tried an approach similar to what I have done for Notepad++ in the past, i.e.
#!/bin/sh
"c:/Program Files (x86)/Notepad++/notepad++.exe" -multiInst -notabbar -nosession -noPlugin "$*"
And used:
#!/bin/sh
"C:\Users\gep13\AppData\Local\Code\app-0.1.0\Code.exe" "$*"
But this results in an error message:
C:\temp\testrepo [master +1 ~0 -0]> git commit
[8660:0504/084217:ERROR:crash_reporter_win.cc(70)] Cannot initialize out-of-process crash handler
Aborting commit due to empty commit message.
C:\temp\testrepo [master +1 ~0 -0]>
Code opens up correctly, with the expected content, but it isn't waiting on the response, i.e. clicking save and closing the window to return to prompt.
UPDATE 2:
I have just heard back from one of the developers working on VSCode. Looks like this functionality currently isn't supported :-(
https://twitter.com/IsidorN/status/595501573880553472
If you are interested in seeing this feature get added, you might want to think about adding your votes here:
UPDATE 3:
I have been reliably informed that this feature has been picked up by the VSCode team, so I am looking forward to a future release that will include it.
UPDATE 4:
Thanks to @f-boucheros comment below, I have been able to get VS Code working as the default editor for commit comments, rebase, etc. I would still like to see if it is possible to use it as the diff tool as well.
UPDATE 5:
As per the accepted answer for the question, this is now possible using the V1.0 release of code.
In the most recent release (v1.0, released in March 2016), you are now able to use VS Code as the default git commit/diff tool. Quoted from the documentations:
- Make sure you can run
code --help
from the command line and you get help.
- if you do not see help, please follow these steps:
- Mac: Select Shell Command: Install 'Code' command in path from the Command Palette.
- Windows: Make sure you selected Add to PATH during the installation.
- Linux: Make sure you installed Code via our new .deb or .rpm packages.
- From the command line, run
git config --global core.editor "code --wait"
Now you can run
git config --global -e
and use VS Code as editor for configuring Git. Add the following to enable support for using VS Code as diff tool:
[diff]
tool = default-difftool
[difftool "default-difftool"]
cmd = code --wait --diff $LOCAL $REMOTE
This leverages the new
--diff
option you can pass to VS Code to compare two files side by side.To summarize, here are some examples of where you can use Git with VS Code:
git rebase HEAD~3 -i
allows to interactive rebase using VS Codegit commit
allows to use VS Code for the commit messagegit add -p
followed bye
for interactive addgit difftool <commit>^ <commit>
allows to use VS Code as diff editor for changes
这篇关于如何使用Visual Studio Code作为Git的默认编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!