简体   繁体   中英

Git ignore except one file type

I have a rule that ignores bin folder (build results):
[Bb]in/

I want git to still add all .txt files, even those in bin directory (but ignore everything else in that dir). How can I achieve this?

Cited from https://git-scm.com/docs/gitignore#_pattern_format

It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn't list excluded directories for performance reasons, so ...

[Bb]in/*
!*.txt

This pattern should find you an answer. If you prepend the negation( ! ) before a pattern, it is marked as not to be ignored irrespective of all the ignores above it. Refer - https://www.atlassian.com/git/tutorials/gitignore

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