简体   繁体   English

如何忽略除顶级目录中的几个文件以及.gitignore的几个目录中的所有内容之外的所有内容

[英]How do I ignore everything except a couple files in the top-level directory and everything in a few directories with .gitignore

I want to ignore everything except a couple files in the top-level directory and everything in a few directories with .gitignore 我想忽略除顶级目录中的几个文件以及.gitignore的几个目录中的所有内容之外的所有内容

My top level .gitignore is: 我的顶级.gitignore是:

* *
!/app/ !/应用/
!gbase.php !gbase.php
!list-secret-prices.php !列表秘密prices.php

The problem is that I have to put a .gitignore with one entry of: 问题是我必须在.gitignore中添加一个条目:
!* !*

in each of the subdirectories that I want to include for it to work. 在我想要包含的每个子目录中工作。 I don't want to have to put a .gitignore in everyone of the directories that I want included. 我不想将.gitignore放在我想要包含的每个目录中。 I want to handle everything in the top level .gitignore. 我想处理顶级.gitignore中的所有内容。

In your case the following might be more appropriate: 在您的情况下,以下可能更合适:

/*
!app/
!gbase.php
!list-secret-prices.php

The first line ignores all top-level directories and files. 第一行忽略所有顶级目录和文件。 Anything inside the ignored directories will also be ignored by git, even if it's not explicitly specified. 忽略目录中的任何内容也将被git忽略,即使它没有明确指定。

The second line unignores the app directory. 第二行取消了app目录的设置。 It will also cause git to find all its files and subdirectories (recursively), because we never told git to ignore anything below the top-level. 它还会导致git找到它的所有文件和子目录(递归),因为我们从未告诉git忽略顶层以下的任何内容。

I make global exclusions in my gitconfig file ($HOME/.gitconfig) 我在我的gitconfig文件中创建了全局排除项($ HOME / .gitconfig)

[core] excludesfile = /Users/meself/.gitignore [core] excludesfile = /Users/meself/.gitignore

And then write my patterns in ~/.gitignore. 然后在〜/ .gitignore中编写我的模式。

Would this help? 这会有帮助吗?

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

相关问题 Make.gitignore 忽略除少数文件外的所有内容 - Make .gitignore ignore everything except a few files 除了几个文件,我如何忽略我回购中的所有内容? - How do I ignore everything in my repo except a few files? .gitignore排除目录下的目录,但不排除顶级文件 - .gitignore exclude directories under directory, but not top-level files 您如何忽略目录以外的所有内容? - How do you gitignore everything except a directory? 如何排除除了所有顶级点文件和子目录之外的所有内容? - How can I exclude everything but all top-level dot files and a subdirectory? 使.git-ftp-ignore忽略所有内容,除了一些文件/目录 - Make .git-ftp-ignore ignore everything except a few files / directories 如何忽略除两个目录(嵌套)之外的所有内容? - How can I ignore everything except two directories (nested)? 无法忽略顶级文件夹及其中的所有内容 - Unable to ignore top-level folder and everything in it recursively 如何在gitignore中编写规则以忽略除某些目录中的目录之外的所有文件? - How can I write a rule in gitignore to ignore all files except directories in some directory? .gitignore 忽略与某些顶级子目录关联的嵌套子目录中具有某些扩展名的文件之外的所有内容 - .gitignore to ignore everything aside from files with certain extensions in nested subdirectories associated with some top level subdirectories
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM