【发布时间】:2021-06-23 08:42:43
【问题描述】:
我正在尝试将 Git 配置为使用 VSCode 作为我的默认编辑器。我的问题是 VSCode 在打开文件后立即退出并将控制权交还给 PowerShell 提示 - 例如,在执行 rebase 时会导致问题。
我知道How to use Visual Studio Code as Default Editor for Git 并且我已经尝试了其中的所有技巧。我觉得那里的答案已经过时了,因为没有一个被接受的答案似乎产生了预期的结果。
首先,为了验证 VSCode 是否符合我的预期,我尝试了
PS C:\src\scp> code --wait
而且它有效。 VSCode 打开,直到我关闭它才返回命令提示符。
然后我尝试了以下所有方法,但它们都对我不起作用。
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.
最后一次绝望的尝试
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.
所以在我看来,这个问题似乎根本不在于 VSCode,而在于 Git 调用编辑器的方式。要么那个,要么我忽略了其他不那么明显的东西。
我使用的版本:
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
我怎样才能让 VSCode 和 Git 一起玩得很好?
更新。
按照一个答案的建议,尝试了更多变体。结果一样。
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.
更新
使用 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.
更新
更新的 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
【问题讨论】:
-
它能在 git-bash 中工作吗?
标签: git powershell visual-studio-code