.gitignore已经有了
由于每次本地运行项目,都会生成新的log文件,但是我并不想提交logs文件夹里面的内容,所以要在.gitignore写logs的规则。
我尝试过添加以下规则
logs/*.log
logs/
/logs/
正确的做法应该是:git rm --cached logs/xx.log.gitignoregit commit -m "We really don't want Git to track this anymore!"
具体的原因如下:
git update-index
所有的团队成员都必须对目标文件执行:
git update-index --assume-unchanged <PATH>fetchgit update-index --assume-unchanged <PATH>pushupdate-indexcloneupdate-index。
首先,git update-index
Register file contents in the working tree to the index(把工作区下的文件内容注册到索引区)
这句话暗含的意思是:update-index
--assume-unchanged
When the "assume unchanged" bit is on, Git stops checking the working tree files for possible modifications, so you need to manually unset the bit to tell Git when you change the working tree file. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).
大致意思是:
手动
lstat
我们知道 Git 不仅仅是用来做代码版本管理的,很多其他领域的项目也会使用 Git。比如说我公司曾经一个客户的项目涉及到精密零件图纸文档的版本管理,他们也用 Git。有一种使用场景是对一些体积庞大的文件进行修改,但是每一次保存 Git 都要计算文件的变化并更新工作区,这在硬盘慢的时候延迟卡顿非常明显。
git update-index --assume-unchanged
git update-index --assume-unchanged,这样 Git 暂时不会理睬你对文件做的修改;- 当你的工作告一段落决定可以提交的时候,重置改标识:
git update-index --no-assume-unchanged,于是 Git 只需要做一次更新,这是完全可以接受的了; - 提交+推送。
另外,根据文档的进一步描述:
coarseuntracked files).
这段描述告诉我们两个事实:
- 虽然可以用其来达成楼主想要的结果,但这是不讲究的做法(coarse);
.gitignore
随之而来的问题是:.gitignore
.gitignoreUntracked Files,也就是那些从来没有被 Git 记录过的文件(自添加以后,从未 add 及 commit 过的文件)。
.log.gitignore
- 从 Git 的数据库中删除对于该文件的追踪;
- .gitignore,让忽略真正生效;
- 提交+推送。
只有这样做,所有的团队成员才会保持一致而不会有后遗症,也只有这样做,其他的团队成员根本不需要做额外的工作来维持对一个文件的改变忽略。
最后有一点需要注意的,git rm --cachedrm+忽略+提交。