简体   繁体   English

忽略子文件夹中的所有文件

[英]Ignore all files except in subfolder

I have a git repo with many files and folder but I want to ignore everything except files and folders in a src folder. 我有一个包含许多文件和文件夹的git repo,但我想忽略src文件夹中除文件和文件夹之外的所有内容。

This is my .gitignore: 这是我的.gitignore:

/*

!**/src/
!.gitignore
!README.md

But this is what git status returns: 但这是git status返回的内容:

$ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore
        README.md

nothing added to commit but untracked files present (use "git add" to track)

So it seems that it is ignoring everything including my src folders. 因此,似乎它正在忽略一切,包括我的src文件夹。

Make sure to ignore files only, not folders: 确保仅忽略文件,而不忽略文件夹:

*
!*/

It is not possible to re-include a file if a parent directory of that file is excluded (even with 2.7 in your case) 如果排除了该文件的父目录 (即使您使用的是2.7) ,则无法重新包含该文件

Then you can exclude the folder src files and subfolders content: 然后,您可以排除文件夹src文件和子文件夹的内容:

!**/src/**

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

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