Skip to content

Instantly share code, notes, and snippets.

@zxhfighter
Last active March 20, 2021 09:36
Show Gist options
  • Save zxhfighter/6320b9a08698bb8703ee to your computer and use it in GitHub Desktop.
Save zxhfighter/6320b9a08698bb8703ee to your computer and use it in GitHub Desktop.
git ignore

.gitignore

有些文件我们不想纳入管理,也不希望它们总出现在未跟踪列表,例如一些开发依赖,编译日志等等。我们可以创建一个.gitignore的文件,列出需要忽略的文件模式。

格式规范

  • 空行或者以注释符号#开头的行会被忽略
  • 标准的glob模式匹配
  • 匹配模式最后跟反斜杠(/)说明要忽略的是目录
  • 要忽略指定模式以外的文件和目录,可以在模式前加上惊叹号(!)取反

例子

# 此为注释,将被Git忽略

# 忽略所有.a结尾的文件
*.a

# 不忽略lib.a
!lib.a

# 忽略/目录下的TODO文件
/TODO

# 忽略build文件夹
build/

# 忽略doc目录下的所有txt文件(不递归)
doc/*.txt

# 忽略doc目录下的所有txt文件(递归)
doc/**/*.txt

参考资料

  1. git - gitignore
  2. gitignore examples
  3. svn - ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment