如何解决gitignore添加失败

如何解决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.

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

newcih

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值