zoukankan      html  css  js  c++  java
  • 【转】git忽略已加入到版本库的文件

    原文:https://www.jianshu.com/p/547916c45142

    ----------------------------

    项目中,我们会用到 '.gitignore' 来忽略一些文件,不记录这些文件的版本控制。

    然而,经常发现,已经添加到了 '.gitignore' 的文件/目录,每次的修改等仍会记录版本。

    产生这种原因,一般都是由于在初始项目时,已经使用 git add 将该文件,加入到了版本库

    如何来从版本库移除呢?

        git rm -r --cached [文件名]
            git rm 的选项:
                -f, --force
                -n, --dry-run                   // 不真实删除,只显示将被删除的文件
                -r                          // 递归删除目录
                --      // 用于将命令行选项和文件列表分开(当文件名和命令行选项比较容易混淆时,很有用!)
                --cached                // 我们本次核心使用,不记录到版本库
                --ignore-unmatch        // 及时没有匹配到要删除的文件,也返回 '0' 状态码(不爆粗)
                -q, --quiet             // 通常 git rm 会将删除结果输出,该选项抑制输出!
     
     
     
        git commit -m "从版本库移除vendor目录"
        git push 
    

    git rm 和 git rm --cached 区别:

        当我们需要删除暂存区或分支上的文件,同时工作区 '不需要' 这个文件,可以使用 'git rm'
            git rm file
            git commit -m 'delete file'
            git push
    
        当我们需要删除暂存区或分支上的文件,但是本地 '需要' 这个文件,只是 '不希望加入版本控制',可以使用 'git rm --cached'
            git rm --cached file
            git commit -m 'delete remote file'
            git push
    

    参考文章:

  • 相关阅读:
    生成器,迭代器
    [LeetCode] Minimum Depth of Binary Tree
    [LeetCode] Sum Root to Leaf Numbers
    [LeetCode]Sort Colors
    [LeetCode] Remove Nth Node From End of List
    [LeetCode] Palindrome Number
    [LeetCode] Container With Most Water
    [LeetCode] Pascal's Triangle II
    [LeetCode] Path Sum
    [LeetCode] Search a 2D Matrix
  • 原文地址:https://www.cnblogs.com/oxspirt/p/15735192.html
Copyright © 2011-2022 走看看