git之gitignore

git中忽略的文件在一个名为.gitignore的特殊文件中被跟踪,该文件在存储库的根目录下签入。没有显式的git ignore命令:相反,当您有要忽略的新文件时,必须手动编辑并提交.gitinore文件。gitignore文件包含与存储库中的文件名匹配的模式,以确定是否应忽略它们。

忽略的文件通常是生成工件和机器生成的文件,这些文件可以从存储库源中派生,或者不应提交。一些常见的例子有:

  • 依赖缓存,例如/node_modules或/packages的内容
  • 编译的代码,例如.o、.pyc和.class文件
  • 生成输出目录,例如/bin、/out或/target
  • 运行时生成的文件,例如.log、.lock或.tmp
  • 隐藏的系统文件,例如.DS\u Store或拇指.db
  • 个人IDE配置文件,如.idea/工作区.xml

Git Ignore模式

.gitignore使用全局模式匹配文件名,可以使用通配符来匹配文件:

Pattern Example matches Explanation*
**/logs logs/debug.log logs/monday/foo.bar build/logs/debug.log 您可以用两个**模式,以匹配存储库中任何位置的目录。
**/logs/debug.log logs/debug.log build/logs/debug.log but not logs/build/debug.log 也可以使用双星号根据文件名和其父目录名匹配文件。
*.log debug.log foo.log .log logs/debug.log 匹配所有后缀为.loog的文件
*.log !important.log debug.log trace.log but not important.log logs/important.log 匹配所有后缀为.loog的文件,important.log除外
*.log !important/*.log trace.* debug.log important/trace.log but not important/debug.log 匹配所有后缀为.log的文件,important目录下除外,trace前缀文件被忽略,既是文件在important目录
/debug.log debug.log but not logs/debug.log 忽略跟目录下的debug.log
debug.log debug.log logs/debug.log 默认忽略所有的debug.log文件
debug?.log debug0.log debugg.log but not debug10.log 忽略一个字符不同debug.log文件
debug[0-9].log debug0.log debug1.log but not debug10.log 忽略debug后跟一个数字,只有一个数字的debug.log文件
debug[01].log debug0.log debug1.log but not debug2.log debug01.log 忽略debug后跟一个数字0或者1,只有一个数字的debug.log文件
debug[!01].log debug2.log but not debug0.log debug1.log debug01.log 可用于匹配除指定集中的字符外的任何字符。
debug[a-z].log debuga.log debugb.log but not debug1.log 范围可以是数字或字母。
logs logs logs/debug.log logs/latest/foo.bar build/logs build/logs/debug.log 如果不附加斜杠,模式将同时匹配具有该名称的文件和目录的内容。在左侧的示例匹配中,将忽略名为logs的目录和文件
logs/ logs/debug.log logs/latest/foo.bar build/logs/foo.bar build/logs/latest/debug.log 附加斜杠表示模式是一个目录。存储库中与该名称匹配的任何目录的全部内容(包括其所有文件和子目录)都将被忽略
logs/ !logs/important.log logs/debug.log logs/important.log 等一下!不应该logs/important.log在左边的例子中被否定
不!由于Git中与性能相关的问题,您不能否定由于模式匹配目录而被忽略的文件
logs/**/debug.log logs/debug.log logs/monday/debug.log logs/monday/pm/debug.log 双星号与零个或多个目录匹配。
logs/*day/debug.log logs/monday/debug.log logs/tuesday/debug.log but not logs/latest/debug.log 通配符也可以用在目录名中。
logs/debug.log logs/debug.log but not debug.log build/logs/debug.log 在特定目录中指定文件的模式是相对于存储库根目录的。(如果愿意,可以在前面加一个斜杠,但它没有什么特别之处。)

这些解释假设.gitignore文件位于存储库的顶层目录中,这是惯例。如果您的存储库有多个.gitignore文件,只需将“repository root”替换为“directory containing the.gitignore文件”(并考虑将它们统一,以确保团队的正常运行)

Golang struct使用内嵌实现继承
tpm: tmux插件管理器
标签:
ajax-loader