.gitignore不生效问题解决方法

工作中工程项目编码时会遇到了一些问题,以此分享。

问题:
工程目录下已创建.gitignore文件,代码编译后会生成各种后缀文件,git status时候会被追踪到这些中间文件,而这些文件又不需要提交,这个时候就需要用.gitignore忽略这些文件

dell@jingjin MINGW64 /e/cardtype/project (master)
$ 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 restore <file>..." to discard changes in working directory)
        modified:   Project/Listings/startup_gd32f30x_hd.lst
        modified:   Project/Master.uvoptx
        modified:   Project/Master.uvprojx
        modified:   Project/Objects/Master.axf
        modified:   Project/Objects/Master.build_log.htm
        modified:   Project/Objects/Master.htm
        modified:   Project/Objects/Master.lnp
        modified:   Project/Objects/Master_Master.dep

.uvoptx
.axf
.htm
.lnp
.dep

解决方法:

git 安装:

Windows下配置Git

1、从git官网下载git:http://git-scm.com/downloads

2、使用默认设置,一直点next即可

3、环境配置:将git的bin路径添加到系统环境变量中。

删除git缓存:

  1. 目录中右键选择git bash Here出现git命令行窗口。

  2. 执行如下指令,采用的是默认的-c,即在输出中显示缓存的文件。可以查看输出的缓存文件中是否存在想要忽略的文件,确实发现存在我想忽略的文件

dell@jingjin MINGW64 /e/cardtype/project (master)
$ git ls-files
.gitignore
CMSIS/core_cm4.h
CMSIS/core_cm4_simd.h
CMSIS/core_cmFunc.h
CMSIS/core_cmInstr.h
CMSIS/gd32f30x.h
CMSIS/startup_gd32f30x_cl.s
CMSIS/startup_gd32f30x_hd.s
CMSIS/startup_gd32f30x_xd.s
CMSIS/system_gd32f30x.c
CMSIS/system_gd32f30x.h
Project/Listings/startup_gd32f30x_hd.lst
Project/Master.uvoptx
Project/Master.uvprojx
Project/Objects/Master.axf
Project/Objects/Master.build_log.htm
Project/Objects/Master.lnp
Project/Objects/Master_Master.dep
  1. 执行如下指令,将对应文件从缓存区中删除
git rm -r --cached xxx(文件名)
  1. 进一步验证文件已删除
git ls-files 

5.使用git命令行进行提交推送

git commit -m .//提交
it push origin master //推送
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

shuiyunjian1

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

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

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

打赏作者

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

抵扣说明:

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

余额充值