如何在 gitignore 中修复 .vscode 跟踪

Sky*_*own 10 git github visual-studio-code

我使用的是遇到问题.gitignore与我.vscode在我的库文件夹中。

我在 my 添加了一条规则.gitignore来忽略我的整个.vscode/文件夹:

# Visual Studio Code # 
.vscode/* 
.vscode/settings.json
!.vscode/settings.json 
!.vscode/tasks.json 
!.vscode/launch.json 
!.vscode/extensions.json 
.history.vscode/settings.json
Run Code Online (Sandbox Code Playgroud)

尽管如此,.vscode我的本地 git 存储库仍在跟踪。我尝试了各种不同的解决方案,包括使用git filter-branch从我的 git 历史记录中删除这个文件夹并git rm --cached .vscode清除我的缓存并重新提交我的更改,但这些解决方案都没有阻止 .vscode 文件夹被 git 跟踪。

当我跑步时,git status我不断得到这个结果:

# Visual Studio Code # 
.vscode/* 
.vscode/settings.json
!.vscode/settings.json 
!.vscode/tasks.json 
!.vscode/launch.json 
!.vscode/extensions.json 
.history.vscode/settings.json
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经通过在git add更改时手动排除此文件夹来解决此问题。

为什么.vscode/仍然显示为未跟踪?如果我要git add .git commit这一点,那就该文件夹时,添加到我的git的历史,最终我的远程存储库我git push。我不希望这种行为发生。

Rau*_*aul 18

有类似的问题,原来文件被添加到我的缓存中。使用以下命令清除它有效。

git rm --cached .vscode/settings.json
Run Code Online (Sandbox Code Playgroud)

参照问题上github上,我找到了解决办法。

  • “致命:pathspec '.vscode/settings.json' 与任何文件都不匹配”:))) (2认同)

m0j*_*0j0 16

也许在你的 .gitignore 中试试这个。这应该忽略整个 .vscode 目录,无论它位于何处。

**/.vscode/
Run Code Online (Sandbox Code Playgroud)