.gitignore 只包含几个文件

##去除哪些路径 
/*
## 保留哪些文件
!my.cnf   //          

学习其他的

*
!/**/
##去除哪些路径
/dirignore1/
/dirignore2/
##只包含哪些结尾的文件
!*.c
!*.h
!*.cpp
!*.sh
!*.xml
!*.py
!*.md
!*.jar
!.scala
!.java

1 * 代表忽略全部

2 /** 代表文件夹下的全部内容 ( A trailing "/" matches everything inside. For example, "abc/" matches all files inside directory "abc")

为什么要写这句,因为不可能包含一个文件,如果他的文件夹都被忽略了 It is not possible to re-include a file if a parent directory of that file is excluded. (*)

3 包含每个文件后,/dirignore1/, 在去除不需要的文件夹。(可以注意到.gitignore是按照顺序读入规则的,顺序重要)

4 ! 在每行前加感叹号,表示需要包括后面的匹配文件或文件夹

5 /, 连续两个* 表示包含文件夹下的所有内容 (A trailing "/" matches everything inside. For example, "abc/**" matches all files inside directory "abc")

6 (只有在没有 “/” 符号的前提下 , 才会作wildcard匹配, 所以模版中不能加"/"这种路径操作) If the pattern does not contain a slash /, Git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file

7, 让Git不再管理当前目录下的某些文件。 ! 取反,

*.h 所有以.h结尾的忽略
!a.h  排除a.h,a.h不被忽略
files/*.py[c | a | d]  files目录下的,.pya,pyb,pyc结尾的忽略

可以从这里下载对应语言的常用.ginigonre文件:https://github.com/github/gitignore

原文链接:https://blog.csdn.net/u011467621/article/details/79108980

posted @ 2021-12-14 14:59  ty1539  阅读(180)  评论(0编辑  收藏  举报