简体   繁体   English

如何在gitignore中选择除特定名称以外的相同格式的多个文件

[英]How to select multiple files of same format except a specific name in gitignore

I have multiple .txt files to include in gitignore. 我有多个.txt文件包含在gitignore中。 Also, I need a few of the .txt files to be commited. 另外,我需要提交一些.txt文件。

Presently, I'm doing: 目前,我正在做:
1) *.txt in .gitignore 1).gitignore中的* .txt
2) Followed by git add -f fill_2_add.txt 2)其次是git add -f fill_2_add.txt

Is there a way to avoid forcefully including the required .txt files? 有没有办法避免强制包含所需的.txt文件? I tried using '!fill_2_add!.txt' as given in documentation but to no avail 我尝试使用文档中给出的'!fill_2_add!.txt',但无济于事

The rules in .gitignore are applied in order and can be negated by starting the line with ! .gitignore中的规则按顺序应用,可以通过以!开头的行来取反! . For your use-case this means you have to first ignore all *.txt files and then list all individual *.txt files you want to include, ie with this .gitignore: 对于您的用例,这意味着您必须首先忽略所有* .txt文件,然后列出要包括的所有单个* .txt文件,即使用此.gitignore:

*.txt
!fill_2_add.txt

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

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