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就不会自动加入到版本控制了。

  • 相关阅读:
    关于一道PHP面试题的解法
    ThinkPHP学习(二)
    ThinkPHP学习(一)
    Apache 创建虚拟主机目录和设置默认访问页面
    awk全集
    初识云计算&openstack
    Python collections
    Python 函数/高阶函数
    Python dic/set/迭代
    python matplotlib 图标绘制
  • 原文地址:https://www.cnblogs.com/xing901022/p/9177213.html
Copyright © 2011-2022 走看看