简体   繁体   中英

How can I gitignore everything except *.txt?

For example. I have a directory containing a mix of txt files and binaries of various extensions, and I only want to version-control the *.txt files

.gitignore:

# ignore everything
*
# but not subdirectories
!*/
# and not .txt files
!*.txt

You can use ! to negate a pattern.

*
!*.txt

for including txt only in directory structure you have to ignore all except (negate) txt, and sub-directory. So make some change on .gitignore.

*
!.gitattributes
!.gitignore
!readme.md
!.gitkeep
!*.txt
!*/

An optional prefix "!" which negates the pattern; any matching file excluded by a previous pattern will become included again. If a negated pattern matches, this will override lower precedence patterns sources. Put a backslash ("\\") in front of the first "!" for patterns that begin with a literal "!", for example, "\\!important!.txt". source

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