I'm trying to configure Git to use VSCode as my default editor. My problem is that VSCode exits and gives control back to the PowerShell Prompt as soon as it opens a file - causing problems when, for example, doing a rebase.
I am aware of How to use Visual Studio Code as Default Editor for Git and I have tried every trick in there. I have a feeling the answer there is outdated since none of the accepted answers seem to produce the desired result.
First, to verify that VSCode does what I expect, I tried
PS C:\src\scp> code --wait
And it works. VSCode opens and not until I close it am I returned to the command prompt.
Then I tried all of the below, and all of them fail to work for me.
PS C:\src\scp> git config --global core.editor "code -w"
PS C:\src\scp> git rebase --continue
Aborting commit due to empty commit message.
error: could not commit staged changes.
PS C:\src\scp> git config --global core.editor "code --wait"
PS C:\src\scp> git rebase --continue
Aborting commit due to empty commit message.
error: could not commit staged changes.
PS C:\src\scp> git config --global core.editor "code --wait --new-window"
PS C:\src\scp> git rebase --continue
Aborting commit due to empty commit message.
error: could not commit staged changes.
And the last desperate attempt
PS C:\src\scp> git config --global core.editor "'C:\Program Files (x86)\Microsoft VS Code\code.exe' -w"
PS C:\src\scp> git rebase --continue
Aborting commit due to empty commit message.
error: could not commit staged changes.
So to me it seems like this problem isn't with VSCode at all, rather it's with the way Git calls the editor. Either that or I'm overlooking something else not-so-obvious.
Versions I use:
VSCode
Version: 1.56.2 (system setup)
Commit: redacted
Date: 2021-05-12T17:13:13.157Z
Electron: 12.0.4
Chrome: 89.0.4389.114
Node.js: 14.16.0
V8: 8.9.255.24-electron.0
OS: Windows_NT x64 10.0.19042
Git
PS C:\src\scp> git --version
git version 2.31.1.windows.1
PowerShell
PS C:\src\scp> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.19041.1023
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1023
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
How can I get VSCode and Git to play nice together?
Update.
Tried a few more variations, as suggested in one answer. Same result.
PS C:\src\scp> git config --global core.editor "powershell -NoProfile -Command code -n --wait"
PS C:\src\scp> git rebase --continue
Aborting commit due to empty commit message.
error: could not commit staged changes.
PS C:\src\scp> git config --global core.editor "cmd /c code -n --wait"
PS C:\src\scp> git rebase --continue
Aborting commit due to empty commit message.
error: could not commit staged changes.
Update
Using CMD
PS C:\src\scp> cmd
Microsoft Windows [Version 10.0.19042.1052]
(c) Microsoft Corporation. All rights reserved.
C:\src\scp>git config --global core.editor "code -w"
C:\src\scp>git rebase --continue
Aborting commit due to empty commit message.
error: could not commit staged changes.
Update
Updated Git
PS C:\src\scp> choco update git
Chocolatey v0.10.15
DEPRECATION NOTICE - choco update is deprecated and will be removed or
replaced in version 1.0.0 with something that performs the functions
of updating package indexes. Please use `choco upgrade` instead.
Upgrading the following packages:
git
By upgrading you accept licenses for the packages.
You have git v2.31.1 installed. Version 2.32.0 is available based on your source(s).
Progress: Downloading git.install 2.32.0... 100%
Progress: Downloading git 2.32.0... 100%
git.install v2.32.0 [Approved]
git.install package files upgrade completed. Performing other installation steps.
The package git.install wants to run 'chocolateyInstall.ps1'.
Note: If you don't run this script, the installation will fail.
Note: To confirm automatically next time, use '-y' or consider:
choco feature enable -n allowGlobalConfirmation
Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): a
Using Git LFS
Installing 64-bit git.install...
git.install has been installed.
git.install installed to 'C:\Program Files\Git'
git.install can be automatically uninstalled.
Environment Vars (like PATH) have changed. Close/reopen your shell to
see the changes (or in powershell/cmd.exe just type `refreshenv`).
The upgrade of git.install was successful.
Software installed to 'C:\Program Files\Git\'
git v2.32.0 [Approved]
git package files upgrade completed. Performing other installation steps.
The upgrade of git was successful.
Software install location not explicitly set, could be in package or
default install location if installer.
Chocolatey upgraded 2/2 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
PS C:\src\scp> git --version
git version 2.32.0.windows.1