.gitignore 对tracked 的文件无效的办法

####问题描述
我在一个先前未被创建.gitignore 的文件夹中,通过命令 touch .gitignore文件,问题来了:尽管制定了若干规则,但是在用git status 查看工作区的状况时,规则之外的文件还是无法忽略。

问题解决的方法

只要用git rm -r - -cached . 删除文件记录
后用 git add . 将工作区的修改提交至暂存区
再用 git commit -m “….” 将暂存区的修改提交至本地库

原因

先来看看一个略官方的gitginore 文档的说明

Two things to keep in mind with ignoring files: First, if a file is already being tracked by Git, adding the file to .gitignore won’t stop Git from tracking it. You’ll need to do git rm –cached < file > to keep the file in your tree and then ignore it. Secondly, empty directories do not get tracked by Git. If you want them to be tracked, they need to have something in them. Usually doing a touch .gitignore is enough to keep the folder tracked.

原文链接在此
文档说用git rm –cached file 可以做到

.gitignore 文件的书写方法
  • 范围由大到小
  • ! + file 要这个文件
  • ?匹配单个字符, * 匹配若干个字符

一起复习下git的使用~

顺便插入张git操作总结图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值