项目中测试环境的配置文件,不能提交,但是每次git status都能看到一堆modify,有没有觉得很烦,哈哈哈哈哈,我们来看看
Git系列的目录如下:
Git常用命令整理一(Git stash)
Git常用命令整理二(Git托管项目)
Git常用命令整理三(Git配置)
Git常用命令整理四(Git删除文件)
Git常用命令整理五(Git疑难杂症)
Git常用命令整理六(创建分支的子分支)
Git常用命令整理七(稀疏检出)
Git常用命令整理八(忽略文件)
Git常用命令整理九(忽略跟踪)
Git常用命令整理十(优雅用法)
Git常用命令整理十一(各种撤回)
1 2 3 4 5 6 7 8 9 10 11 12 13 | git status On branch master Your branch is up to date with 'origin/master' . Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: conf /config .php modified: conf /db/cluster .conf modified: conf /redis .conf modified: php /etc/php-fpm .conf modified: php /etc/php .ini |
这个时候就可以设置忽略跟踪某些文件
一、忽略跟踪文件
1、命令
1 | git update-index --assume-unchanged 路径/文件 |
2、例子
1 2 3 4 5 | git update-index --assume-unchanged conf /config .php git update-index --assume-unchanged conf /db/cluster .conf git update-index --assume-unchanged conf /redis .conf git update-index --assume-unchanged php /etc/php-fpm .conf git update-index --assume-unchanged php /etc/php .ini |
这个时候在查看就不可见了
二、恢复忽略
1、命令
1 | git update-index --no-assume-unchanged 路径/文件 |
2、例子
1 | git update-index --no-assume-unchanged conf /config .php |
三、已commit的文件,忽略跟踪
1 2 | git rm -r --cached xxx git commit -a -m "删除不需要的文件" |