zoukankan      html  css  js  c++  java
  • git如何忽略已经加入版本控制的文件

    git移除已经追踪的文件

    有时候新增一个文件,会自动追加到git的版本控制当中,但是又不想提交到仓库。可以按照下面的步骤:

    git status
    

    查看管理状态:

    ml-py git:(master) ✗ git status
    On branch master
    Your branch is up to date with 'origin/master'.
    
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
            new file:   work-testing/01-sex-predict/data.tg
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    
            .idea/misc.xml
            .idea/ml-py.iml
            .idea/modules.xml
            .idea/workspace.xml
    

    其中data.tg就是我不想提交的文件,但是现在已经进入到版本控制当中了。

    那么可以通过rm删除当前的控制状态:

    ml-py git:(master) ✗ git rm --cached work-testing/01-sex-predict/data.tg
    rm 'work-testing/01-sex-predict/data.tg'
    

    再次查看就发现已经到了未加入版本控制状态列表里面

    ➜  ml-py git:(master) ✗ git status
    On branch master
    Your branch is up to date with 'origin/master'.
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    
            .idea/misc.xml
            .idea/ml-py.iml
            .idea/modules.xml
            .idea/workspace.xml
            work-testing/
    
    nothing added to commit but untracked files present (use "git add" to track)
    

    然后把该文件添加到.gitignore里面就可以了。有时候工程初始化并没有.gitignore文件,可以自己创建一个:

    touch .gitignore
    

    然后手动编辑即可:

    # 敏感数据
    *.tg
    
    # 排除工程文件
    .idea/
    

    提交后,以后再创建的xxx.tg就不会自动加入到版本控制了。

  • 相关阅读:
    mysq foreign外键记录
    查询时隐藏部分身份证号
    SpringBoot接收前端参数
    RabbbitMQ安装
    @configurationProperties注解时 idea弹出 Spring Boot Annotion processor not found in classpath
    rpm,yum和apt使用详解
    python人脸识别
    Fuchsia文章汇总
    Androi O Automotive 介绍
    Linux 版本控制工具之rabbitvcs
  • 原文地址:https://www.cnblogs.com/xing901022/p/9177213.html
Copyright © 2011-2022 走看看