$ mkdir doc #创建一个doc文件夹 $ echo 'hi' > doc/ignoret #在doc文件夹下创建一个文件 $ git status #查看状态 提示doc目录未被追踪 需要add On branch temp Untracked files: (use "git add <file>..." to include in what will be committed)
doc/ $ vi .gitignore #在工程根目录创建.gitignore文件 写入doc 保存退出 $ git status #查看状态 doc目录不会再被提示未被追踪 说明Git不再管理doc目录 On branch temp Untracked files: (use "git add <file>..." to include in what will be committed)
.gitignore
$ vi .gitignore #在把doc修改为doc/ $ git status #查看状态 doc目录依然不被Git所管理 On branch temp Untracked files: (use "git add <file>..." to include in what will be committed)
.gitignore
$ rm -rf doc #删除doc文件夹 $ echo 'This is file.' > doc #创建doc文件 $ cat .gitignore doc/ $ git status #doc文件还是会被Git管理的 On branch temp Untracked files: (use "git add <file>..." to include in what will be committed)
.gitignore doc
$ vi .gitignore #如果也不想让Git管理doc文件,那么把doc改成doc/就可以了 $ git status On branch temp Untracked files: (use "git add <file>..." to include in what will be committed)
.gitignore
$ mv .gitignore doc.gitignore #将.gitignore文件名修改为doc.gitignore $ git status #查看状态 doc就会重新被Git管理 所以文件名必须要是.gitignore On branch temp Untracked files: (use "git add <file>..." to include in what will be committed)