700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 如何使用Visual Studio Code作为Git的默认编辑器

如何使用Visual Studio Code作为Git的默认编辑器

时间:2021-02-11 17:06:09

相关推荐

如何使用Visual Studio Code作为Git的默认编辑器

本文翻译自:How to use Visual Studio Code as Default Editor for Git

When using git at the command line, I am wondering if it is possible to use Visual Studio Code as the default editor, ie when creating commit comments, and looking at a diff of a file from the command line.在命令行上使用git时,我想知道是否可以将Visual Studio Code用作默认编辑器,即创建提交注释并从命令行查看文件的差异时。

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?我知道将无法使用它进行合并(至少在当前时间),但是没有人知道是否可以使用它来查看差异,如果可以的话,将需要使用哪些命令行选项.gitconfig文件来实现这一目标?

UPDATE 1:更新1:

I have tried an approach similar to what I have done for Notepad++ in the past , ie我尝试过一种类似于过去对Notepad ++所做的方法,即

#!/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:(70)] Cannot initialize out-of-process crash handlerAborting 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, ie clicking save and closing the window to return to prompt.代码会正确打开,并包含预期的内容,但它不会等待响应,即单击“保存”并关闭窗口以返回提示。

UPDATE 2:更新2:

I have just heard back from one of the developers working on VSCode.我刚刚从一位从事VSCode的开发人员那里听到回音。Looks like this functionality currently isn't supported :-(似乎当前不支持此功能:-(

/IsidorN/status/595501573880553472/IsidorN/status/595501573880553472

If you are interested in seeing this feature get added, you might want to think about adding your votes here:如果您有兴趣添加此功能,则可以考虑在此处添加投票:

/forums/293070-visual-studio-code/suggestions/7756482-support-git-configure-diff-and-merge-tools/forums/293070-visual-studio-code/suggestions/7756482-support-git-configure-diff-and-merge-tools

UPDATE 3:更新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.我已经可靠地得知该功能已由VSCode团队使用,因此我期待将来的版本将包含该功能。

UPDATE 4:更新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.感谢下面的@ f-boucheros注释,我得以使VS Code成为提交注释,变基等的默认编辑器。我仍然想看看是否也可以将其用作diff工具。

UPDATE 5:更新5:

As per the accepted answer for the question, this is now possible using the V1.0 release of code.根据问题的公认答案,现在可以使用V1.0版本的代码来实现。

#1楼

参考:/question/21yhl/如何使用Visual-Studio-Code作为Git的默认编辑器

#2楼

Im not sure you can do this, however you can try these additions in your gitconfig file.我不确定您可以执行此操作,但是可以在gitconfig文件中尝试这些添加。

Try to replace the kdiff3 from these values to point to visual studio code executable.尝试从这些值替换kdiff3以指向Visual Studio代码可执行文件。

[merge] tool = kdiff3 [mergetool "kdiff3"] path = C:/Program Files/KDiff3/kdiff3.exe keepBackup = false trustExitCode = false

#3楼

I opened up my.gitconfigand amended it with:我打开了我的.gitconfig并修改为:

[core]editor = 'C:/Users/miqid/AppData/Local/Code/app-0.1.0/Code.exe'

That did it for me (I'm on Windows 8).这样做对我有用(我在Windows 8上)。

However, I noticed that after I tried an arbitrarygit committhat in myGit Bashconsole I see the following message:但是,我注意到在尝试在Git Bash控制台中git commit任意git commit,我看到以下消息:

[9168:0504/160114:INFO:(212)] Renderer process started

Unsure of what the ramifications of this might be.不确定这可能会带来什么后果。

#4楼

GitPad sets your current text editor as the default editor for Git.GitPad将您当前的文本编辑器设置为Git的默认编辑器。

My default editor for.txtfiles in Windows 10 is Visual Studio Code and running GitPad once made it the default editor for Git.我在Windows 10中用于.txt文件的默认编辑器是Visual Studio Code,运行GitPad使其成为Git的默认编辑器。I haven't experienced the problems mentioned in the question (Git waits until VS Code window is closed in my case).我还没有遇到问题中提到的问题(Git等到我关闭了VS Code窗口)。

(The link for the.exefile didn't work for me, you may need to compile the source yourself.)(.exe文件的链接对我不起作用,您可能需要自己编译源代码。)

#5楼

I set up Visual Studio Code as a default to open .txt file.我将Visual Studio Code设置为默认打开.txt文件。And next I did use simple command:git config --global core.editor "'C:\\Users\\UserName\\AppData\\Local\\Code\\app-0.7.10\\Code.exe\\'".接下来我确实使用了简单的命令:git config --global core.editor "'C:\\Users\\UserName\\AppData\\Local\\Code\\app-0.7.10\\Code.exe\\'"。And everything works pretty well.一切都很好。

#6楼

For what I understand, VSCode is not in AppData anymore.据我了解,VSCode不在AppData中。

So Set the default git editor by executing that command in a command prompt window:因此,通过在命令提示符窗口中执行该命令来设置默认的git编辑器:

git config --global core.editor "'C:\Program Files (x86)\Microsoft VS Code\code.exe' -w"

The parameter-w,--waitis to wait for window to be closed before returning.参数-w,----wait将等待窗口关闭后再返回。Visual Studio Code is base on Atom Editor.Visual Studio代码基于Atom编辑器。if you also have atom installed execute the commandatom --help.如果还安装了atom --help执行命令atom --help。You will see the last argument in the help is wait.您将看到帮助中的最后一个参数是等待。

Next time you do agit rebase -i HEAD~3it will popup Visual Studio Code.下次您执行git rebase -i HEAD~3,将弹出Visual Studio Code。Once VSCode is close then Git will take back the lead.VSCode关闭后,Git将重新获得领先。

Note: My current version of VSCode is 0.9.2注意:我当前的VSCode版本是0.9.2

I hope that help.希望对您有所帮助。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。