简体   繁体   中英

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. In that top-level one I want to ignore all files except for the 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. Git will see changes to .vscode/launch.json and you'll be prompted to commit them just like any other file.

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:

.vscode
!.vscode/launch.json

(You added a slash after !, so the path was considered absolute).

Simply put these 2 lines in your .gitignore

.vscode/*
!.vscode/launch.json

First line means, ignore .vscode folder with all (using * symbol after / ) of its files. Second line means, exclude (using ! ) launch.json file whereas inside the .vscode folder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM