简体   繁体   English

Gitignore:忽略所有 .vscode 目录,但包括顶级 launch.json

[英]Gitignore: Ignore all .vscode directories, but include the top-level launch.json

I want to ignore all .vscode directories that may show up in my repository, except for the top-level one.我想忽略可能出现在我的存储库中的所有.vscode目录,除了顶级目录。 In that top-level one I want to ignore all files except for the launch.json .在那个顶级文件中,我想忽略除launch.json之外的所有文件。

I tried to no extent:我没有尝试过:

**/.vscode/
!/.vscode/
/.vscode/*
!/.vscode/launch.json
**/.vscode/
!/.vscode/
!/.vscode/launch.json
**/.vscode/
!/.vscode/launch.json
**/.vscode/*
!/.vscode/launch.json
**/.vscode/
/.vscode/!launch.json

I'd recommend simply ignoring all of these directories:我建议简单地忽略所有这些目录:

.vscode/

and then manually tracking the file you want :然后 手动跟踪您想要的文件

git add -f .vscode/launch.json

The -f adds files even if they're ignored, and once the file is tracked the ignore has no effect on it. -f会添加文件,即使它们被忽略,一旦文件被跟踪,忽略就不会对其产生影响。 Git will see changes to .vscode/launch.json and you'll be prompted to commit them just like any other file. Git 将看到对.vscode/launch.json更改,并且系统会提示您像提交任何其他文件一样提交它们。

I stumbled on this answer and as some sources today claim that its a good idea to commit the launch.json I wanted to provide the correct answer:我偶然发现了这个答案,正如今天的一些消息来源声称提交launch.json是个好主意,我想提供正确的答案:

.vscode
!.vscode/launch.json

(You added a slash after !, so the path was considered absolute). (您在 ! 之后添加了一个斜杠,因此该路径被视为绝对路径)。

Simply put these 2 lines in your .gitignore只需将这两行放在您的.gitignore

.vscode/*
!.vscode/launch.json

First line means, ignore .vscode folder with all (using * symbol after / ) of its files.第一行表示,忽略.vscode文件夹及其所有文件(在/之后使用*符号)。 Second line means, exclude (using ! ) launch.json file whereas inside the .vscode folder第二行表示排除(使用!launch.json文件,而在.vscode文件夹中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何忽略除顶级目录中的几个文件以及.gitignore的几个目录中的所有内容之外的所有内容 - How do I ignore everything except a couple files in the top-level directory and everything in a few directories with .gitignore .gitignore排除目录下的目录,但不排除顶级文件 - .gitignore exclude directories under directory, but not top-level files 除了顶层以外,如何使用.gitignore排除文件类型? - How to exclude a filetype with .gitignore except in the top-level? 无法忽略顶级文件夹及其中的所有内容 - Unable to ignore top-level folder and everything in it recursively 让 .gitignore 不忽略顶级目录中的 .htaccess 文件 - Have .gitignore to NOT ignore an .htaccess file within top level directory 如何最终通过.gitignore忽略所有子目录中的文件 - How to finally ignore a file in all sub-directories via .gitignore gitignore模式,以包含具有特定子目录的所有目录 - gitignore pattern to include all directories with a specific sub directory Gitignore语法忽略动态目录 - Gitignore Syntax to Ignore Dynamic Directories Git:所有文件都在子目录中,但它们应该是顶级的 - Git: all files are in a subdirectory, but they should be top-level .gitignore无法忽略文件​​夹目录或文件 - .gitignore can't ignore folder directories or files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM