我在我的项目中安装了husky。然后我运行了precommit
命令。现在,当我运行git
命令时,它不起作用,而是问我你想用什么打开这个文件。所以,我使用npm prune
移除了husky,然后从项目目录的/.git
中删除了hooks文件夹,但仍然没有帮助。我正在使用Windows 10。
我在我的项目中安装了husky。然后我运行了precommit
命令。现在,当我运行git
命令时,它不起作用,而是问我你想用什么打开这个文件。所以,我使用npm prune
移除了husky,然后从项目目录的/.git
中删除了hooks文件夹,但仍然没有帮助。我正在使用Windows 10。
首先,在内置终端中键入:git --version
。
如果该命令无法正常工作,请下载并安装最新版本的Git。否则,在VS Code的扩展中,在搜索栏中键入:@builtin
。这将列出VS Code中所有内置扩展,按不同部分进行分类。在“功能”部分中查找 Git 扩展程序。检查是否已禁用该扩展程序。启用它,你的版本控制应该就可以开始工作了。
我遇到了一个类似的问题 - VS Code 与 Git 的配合出现了问题(例如:没有变更检测,从远程获取时出现问题),但我找不到导致这个问题的原因(我没有像 OP 那样安装 Husky)。
受 @user9795515's answer 的启发,我通过重新启动 VSC 中的 Git 功能解决了 Git 的问题:
尝试从终端检查是否识别Git命令。
目前我正在使用Powershell终端。
git --version
应该返回类似于git version 2.28.0.windows.1
的内容。
如果这不起作用,请尝试以下步骤:
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"args": ["-NoExit", "-ExecutionPolicy", "Unrestricted", "-NoProfile", "-File", "C:\\Users\\LENOVO\\Documents\\WindowsPowerShell\\bootstrap-git.profile.ps1"],
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"Git Bash": {
"source": "Git Bash"
}
}
git --version
命令。bootstrap-git.profile.ps1
文件中,该文件在第二步中使用。# Start a transcript
#
if (!(Test-Path "$Env:USERPROFILE\Documents\WindowsPowerShell\Transcripts"))
{
if (!(Test-Path "$Env:USERPROFILE\Documents\WindowsPowerShell"))
{
$rc = New-Item -Path "$Env:USERPROFILE\Documents\WindowsPowerShell" -ItemType directory
}
$rc = New-Item -Path "$Env:USERPROFILE\Documents\WindowsPowerShell\Transcripts" -ItemType directory
}
$curdate = $(get-date -Format "yyyyMMddhhmmss")
Start-Transcript -Path "$Env:USERPROFILE\Documents\WindowsPowerShell\Transcripts\PowerShell_transcript.$curdate.txt"
# Alias Git
#
New-Alias -Name git -Value "$Env:ProgramFiles\Git\bin\git.exe"
或者,如果您已经安装了Git,则尝试在VS Code中使用Git Bash终端。
我曾遇到同样的问题,但是我的 git --version
在命令提示符中可以使用。
我将 C:\Program Files\Git\bin
和 C:\Program Files\Git\cmd
设置到了 PATH
中(在 Windows 系统下 -> 环境变量 -> PATH),然后重新启动了命令提示符和 Visual Studio Code,问题得到了修复。
请在终端中运行git config --global safe.directory *
。