Git基础(三) 跟踪文件

 

  • 检查当前文件状态
git status
  • 跟踪新文件
git add README
  • 状态简览
git status -s

git status --short
  • 忽略文件

创建一个名为.gitignore的文件,列出要忽略的文件模式

cat .gitignore

文件.gitignore的格式规范如下

  1. 所有空行或者以#开头的行都会被Git忽略
  2. 所有使用标准的glob模式匹配
  3. 匹配模式可以以(/)开头防止递归
  4. 匹配模式可以以(/)结尾指定目录
  5. 要忽略指定模式以外的文件或目录,可以在模式前加上感叹号(!)取反

所谓的glob模式是指shell所使用的简化了的正则表达式。

  1. 星号(*)匹配零个或多个任意字符
  2. [abc]匹配任何一个列在方括号中的字符
  3. 问号(?)只匹配一个任意字符
  4. 如果方括号中使用短横线分隔两个字符,表示所有在这两个字符范围内的都可以匹配(比如[0-9]表示匹配所有0到9的数字)
  5. 使用两个星号(**)表示匹配任意中间目录,比如“a/**/z”可以匹配a/z,a/b/z或z/b/c/z等

看一个.gitignore文件的例子

# no .a files
*.a
# but do track lib.a, even though you're ignoring .a files above
!lib.a
# only ignore the TODO file in the current directory, not subdir/TODO
/TODO
# ignore all files in the build/ directory
build/
# ignore doc/notes.txt, but not doc/server/arch.txt
doc/*.txt
# ignore all .pdf files in the doc/ directory
doc/**/*.pdf

 

posted @ 2018-06-05 19:03  梦醒江南·Infinite  阅读(366)  评论(0编辑  收藏  举报