I have the following .gitignore file:
# Ignore everything
*
# But not these
!.gitignore
!Code
!Materials
The intention is to ignore everything except the .gitignore file itself, and everything under the Code and Materials directories. Somehow when I open SourceTree, the .gitignore file is properly excluded, but the Code and Materials directories are ignored. What did I do wrong?
*
matches every file in those directories as well (and Git doesn't keep track of empty directories). You can ignore just the top level:
# Ignore everything
/*
# But not these
!/.gitignore
!/Code
!/Materials
Paths like /Code/example.cs
won't be matched by /*
, because *
can only represent one path component, but a simple *
without the /
will match the example.cs
component of /Code/example.cs
.
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.