如何解决gitignore添加失败
题前文
如果在.gitignore
文件中,添加的文件没有被ignore,是的,文件已经被git给track了,导致忽略失败。但是,目前百度出来的方案,全是清一色的下列步骤
git rm -r --cached XXX
git add .
git commit
这是错误的方法!!!
你试试看,在团队项目里面,这样做,你迟早会把他给push到远端。你就因为自己要忽略文件失败,然后给远程推送这些玩意儿的提交?你确定这样做,不会被削?
正确的解决办法
git update-index --assume-unchanged XXXX
关于update-index
的官方文档,可通过以下命令查看,以保证正确服用~
git help git-update-index
这里摘抄出来,官方关于update-index
的这个assume-unchanged
的说明
When this flag is specified, the object names recorded for the paths are not updated. Instead, this option sets/unsets the “assume unchanged” bit for the paths. When the “assume unchanged” bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index. If you want to change the working tree file, you need to unset the bit to tell Git. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).
Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.