# Blocklist files/folders in same directory as the .gitignore file /*
# Includelist some files !.gitignore !README.md
# Ignore all files named .DS_Store or ending with .log **/.DS_Store **/*.log
# Includelist folder/a/b1/ and folder/a/b2/ # trailing "/" is optional for folders, may match file though. # "/" is NOT optional when followed by a * !folder/ folder/* !folder/a/ folder/a/* !folder/a/b1/ !folder/a/b2/ !folder/a/file.txt
核心代码
忽略所有文件,包含特定文件
1 2 3
* !.gitignore !someFile.txt
忽略嵌套目录下的所有文件,包含特定文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# Skip all files *
# But not `aDir/anotherDir/someOtherDir/aDir/bDir/cDir/a.txt` !aDir/ aDir/* !aDir/anotherDir/ aDir/anotherDir/* !aDir/anotherDir/someOtherDir/ aDir/anotherDir/someOtherDir/* !aDir/anotherDir/someOtherDir/aDir/ aDir/anotherDir/someOtherDir/aDir/* !aDir/anotherDir/someOtherDir/aDir/bDir/ aDir/anotherDir/someOtherDir/aDir/bDir/* !aDir/anotherDir/someOtherDir/aDir/bDir/cDir/ aDir/anotherDir/someOtherDir/aDir/bDir/cDir/* !aDir/anotherDir/someOtherDir/aDir/bDir/cDir/a.txt