gitignore-文件通用参考版本

案例一

  • /mtk/,过滤整个文件夹
  • *.zip,过滤所有.zip 文件
  • /mtk/do.c,过滤某个具体文件

案例二

只需要管理 /mtk/ 目录中的 one.txt 文件,这个目录中的其他文件都不需要管理:

1
2
/mtk/
!/mtk/one.txt

注意:

  1. git 对于 .ignore 配置文件是按行从上到下进行规则匹配的,如果前面的规则匹配的范围更大,则后面的规则将不会生效。
  2. 如果在创建 .gitignore 文件之前 push,即使在 .gitignore 文件中写入新的过滤规则,这些规则也不会起作用,Git 仍然会对所有文件进行版本管理。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

.gradle
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
HELP.md

# STS
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

# IntelliJ IDEA
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

# NetBeans
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

# VS Code
.vscode/

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*