云主机 网站指南百度网页链接
.gitignore 文件是用来告诉 Git 哪些文件或目录不应该被跟踪的。下面是一些常见的 .gitignore 文件语法规则:
-  
空行或以
#开头的行将被 Git 忽略,可以用作注释。 -  
星号
*代表零个或多个任意字符。例如,*.txt会匹配所有的.txt文件。 -  
问号
?代表一个任意字符。例如,?.txt会匹配a.txt但不会匹配ab.txt。 -  
方括号
[]可以匹配括号内的任一字符。例如,[abc].txt会匹配a.txt,b.txt和c.txt。 -  
两个星号
**表示任意中间目录。例如,**/foo会匹配foo,a/foo,a/b/foo等。 -  
前缀
!表示不忽略。例如,*.txt和!important.txt会忽略所有的.txt文件,但不会忽略important.txt。 -  
前缀
/表示只忽略当前目录下的文件。例如,/test会忽略当前目录下的test文件,但不会忽略a/test。 -  
后缀
/表示只忽略目录。例如,test/会忽略test目录,但不会忽略test文件。 
你可以在 .gitignore 文件中使用这些规则来指定哪些文件或目录应该被 Git 忽略。这是一个典型的 .gitignore 文件示例:
# Ignore all .txt files
*.txt# But don't ignore important.txt
!important.txt# Only ignore the test directory in the current directory
/test# Ignore any file named test anywhere in the repo
**/test# Ignore all files in any directory named build
**/build/
 
记住,一旦一个文件被 Git 跟踪,就算你在 .gitignore 文件中添加了匹配的规则,它也不会被 Git 忽略。要使 Git 忽略已经被跟踪的文件,你需要先使用 git rm --cached 命令将其从 Git 的跟踪列表中移除。
