development

Git의 기본 편집기로 Visual Studio Code를 사용하는 방법

big-blog 2020. 3. 17. 23:35
반응형

Git의 기본 편집기로 Visual Studio Code를 사용하는 방법


커맨드 라인에서 git을 사용할 때 Visual Studio Code를 기본 편집기로 사용할 수 있는지, 즉 커밋 주석을 만들고 커맨드 라인에서 파일의 diff를 볼 수 있는지 궁금합니다.

병합을 수행하는 데 (최소 1 분) 사용할 수는 없지만 diff를 볼 때 사용할 수 있는지, 그렇다면 명령 줄 옵션이 필요한지 알고 있습니다. 이를 위해 .gitconfig 파일?

업데이트 1 :

나는에 대해 수행 한 것과 유사한 접근 시도 과거에 메모장 + + , 즉

#!/bin/sh

"c:/Program Files (x86)/Notepad++/notepad++.exe" -multiInst -notabbar -nosession -noPlugin "$*"

그리고 사용 :

#!/bin/sh

"C:\Users\gep13\AppData\Local\Code\app-0.1.0\Code.exe" "$*"

그러나 이로 인해 오류 메시지가 나타납니다.

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]>

코드가 예상 내용과 함께 올바르게 열리지 만 응답을 기다리는 중이 아닙니다. 즉, 저장을 클릭하고 창을 닫아 프롬프트로 돌아갑니다.

업데이트 2 :

VSCode를 개발하는 개발자 중 한 사람으로부터 방금 들었습니다. 이 기능은 현재 지원되지 않는 것 같습니다 :-(

https://twitter.com/IsidorN/status/595501573880553472

이 기능이 추가되는 것을보고 싶다면 여기에 투표를 추가하는 것이 좋습니다.

http://visualstudio.uservoice.com/forums/293070-visual-studio-code/suggestions/7756482-support-git-configure-diff-and-merge-tools

업데이트 3 :

나는 한 안정적으로 통보 나는 그것을 포함하는 향후의 릴리스로 기대 때문에이 기능은 VSCode 팀에 의해 포착되었습니다.

업데이트 4 :

아래의 @ f-boucheros 주석 덕분에 VS Code가 커밋 주석, rebase 등의 기본 편집기로 작동하도록 할 수있었습니다. diff 도구로도 사용할 수 있는지 여전히 확인하고 싶습니다.

업데이트 5 :

질문에 대한 답변으로 V1.0 릴리스 코드를 사용하여 가능합니다.


최신 릴리스 ( 2016 년 3 월에 릴리스 된 v1.0 )에서 VS 코드를 기본 git commit / diff 도구로 사용할 수 있습니다. 문서에서 인용 :

  1. code --help명령 행에서 실행할 수 있는지 확인 하고 도움을 받으십시오.

    • 도움말이 보이지 않으면 다음 단계를 따르십시오.

      • Mac : Shell Command 선택 : Command Palette 에서 경로에 'Code'명령을 설치 하십시오 .

        • 명령 팔레트는 VS 코드 내부에서 shift+ + 를 누르면 팝업됩니다 P. ( Windows의 경우 shift+ ctrl+ P)
      • Windows : 설치 중에 PATH에 추가를 선택했는지 확인하십시오 .
      • Linux : 새로운 .deb 또는 .rpm 패키지를 통해 Code를 설치했는지 확인하십시오.
  2. 명령 행에서 다음을 실행하십시오. git config --global core.editor "code --wait"

이제 git config --global -eGit 구성을위한 편집기로 VS Code를 실행 하고 사용할 수 있습니다 . 여기에 이미지 설명을 입력하십시오VS 코드를 diff 도구로 사용하는 기능을 지원하려면 다음을 추가하십시오.

[diff]
    tool = default-difftool
[difftool "default-difftool"]
    cmd = code --wait --diff $LOCAL $REMOTE

이것은 --diffVS 코드로 전달하여 두 파일을 나란히 비교할 수 있는 새로운 옵션을 활용합니다 .

요약하자면 다음은 VS 코드와 함께 Git을 사용할 수있는 몇 가지 예입니다.

  • git rebase HEAD~3 -i VS 코드를 사용하여 대화식 리베이스 가능
  • git commit 커밋 메시지에 VS 코드를 사용할 수 있습니다.
  • git add -p다음에 e대화 형 추가에 대한
  • git difftool <commit>^ <commit> VS 코드를 변경을 위해 diff 편집기로 사용할 수 있습니다

내가 이해하기 위해 VSCode는 더 이상 AppData에 없습니다.

따라서 명령 프롬프트 창에서 해당 명령을 실행하여 기본 git 편집기를 설정하십시오.

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

The parameter -w, --wait is to wait for window to be closed before returning. Visual Studio Code is base on Atom Editor. if you also have atom installed execute the command atom --help. You will see the last argument in the help is wait.

Next time you do a git rebase -i HEAD~3 it will popup Visual Studio Code. Once VSCode is close then Git will take back the lead.

Note: My current version of VSCode is 0.9.2

I hope that help.


You need to use command:

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

Make sure you can start your editor from Git Bash

If you want to use Code.exe with short path, you can do this by adding the following line to your .bash_profile:

alias vscode="C:/Program\ Files/Microsoft\ VS\ Code/Code.exe"

And now, you can call it using only vscode command(or whatever you named it)

Some additional info:

Setup will add Visual Studio Code to your %PATH%, so from the console you can type 'code' to open VS Code on that folder. You will need to restart your console after the installation for the change to the %PATH% environmental variable to take effect.


Another useful option is to set EDITOR environment variable. This environment variable is used by many utilities to know what editor to use. Git also uses it if no core.editor is set.

You can set it for current session using:

export EDITOR=code --wait

This way not only git, but many other applications will use VS Code as editor.

To make this change permanent, add this to ~/.profile for example. See this question for more options.


I opened up my .gitconfig and amended it with:

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

That did it for me (I'm on Windows 8).

However, I noticed that after I tried an arbitrary git commit that in my Git Bash console I see the following message:

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

Unsure of what the ramifications of this might be.


GitPad sets your current text editor as the default editor for Git.

My default editor for .txt files in Windows 10 is Visual Studio Code and running GitPad once made it the default editor for Git. I haven't experienced the problems mentioned in the question (Git waits until VS Code window is closed in my case).

(The link for the .exe file didn't work for me, you may need to compile the source yourself.)


Good news! At the time of writing, this feature has already been implemented in the 0.10.12-insiders release and carried out through 0.10.14-insiders. Hence we are going to have it in the upcoming version 1.0 Release of VS Code.

Implementation Ref: Implement -w/--wait command line arg


Run this command in your Mac Terminal app

git config --global core.editor "/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code"

Just want to add these back slashes to previous answers, I am on Windows 10 CMD, and it doesn't work without back slashes before the spaces.

git config --global core.editor "C:\\Users\\your_user_name\\AppData\\Local\\Programs\\Microsoft\ VS\ Code\\Code.exe"

Im not sure you can do this, however you can try these additions in your gitconfig file.

Try to replace the kdiff3 from these values to point to visual studio code executable.

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


.txt 파일을 열려면 Visual Studio Code를 기본값으로 설정했습니다. 그리고 다음은 간단한 명령을 사용했습니다 git config --global core.editor "'C:\Users\UserName\AppData\Local\Code\app-0.7.10\Code.exe\'". 그리고 모든 것이 잘 작동합니다.


64 비트 내부자 버전을 사용하는 Windows 10에서 명령은 다음과 같아야합니다.

git config --global core.editor " 'C : \ Program Files \ Microsoft VS Code Insiders \ bin \ code-insiders.cmd'"

'Program Files'디렉토리에서 'code-insiders.cmd'의 이름을 'code.cmd'로 바꿀 수도 있습니다. 이런 방식으로 이제 'code'명령을 사용할 수 있습니다. 에서 파일 편집을 시작합니다. 예배 규칙서

참고 URL : https://stackoverflow.com/questions/30024353/how-to-use-visual-studio-code-as-default-editor-for-git

반응형