Git add ignore

What’s gitignore for:

The files which you don’t want to upload or list in your git history, such as “.DS_store” or some other data files. You can achieve this by adding the .gitignore file into your git repo.

Mac .DS_store

gitignore can set globally or just add a single file into your repo. You can find the doc in this link.

  • 所有空行或者以注释符号 # 开头的行都会被 git 忽略,空行可以为了可读性分隔段落,# 表明注释。
  • 第一个 / 会匹配路径的根目录,举个栗子,”/*.html”会匹配”index.html”,而不是”d/index.html”。
  • 通配符 匹配任意个任意字符,? 匹配一个任意字符。需要注意的是通配符不会匹配文件路径中的 /,举个栗子,”d/.html”会匹配”d/index.html”,但不会匹配”d/a/b/c/index.html”。
  • 两个连续的星号 ** 有特殊含义:
    • / 开头表示匹配所有的文件夹,例如 /test.md 匹配所有的test.md文件。
    • 以 / 结尾表示匹配文件夹内所有内容,例如 a/ 匹配文件夹a中所有内容。
    • 连续星号 前后分别被 / 夹住表示匹配0或者多层文件夹,例如 a//b 匹配到 a/b 、a/x/b 、a/x/y/b 等。
  • 前缀 ! 的模式表示如果前面匹配到被忽略,则重新添加回来。如果匹配到的父文件夹还是忽略状态,该文件还是保持忽略状态。如果路径名第一个字符为 ! ,则需要在前面增加 \ 进行转义。

Reference