Ignore files that have already been committed to a Git repository

This question already has an answer here:

  • How to make Git “forget” about a file that was tracked but is now in .gitignore? 17 answers

  • To untrack a single file that has already been added/initialized to your repository, ie, stop tracking the file but not delete it from your system use: git rm --cached filename

    To untrack every file that is now in your .gitignore :

    First commit any outstanding code changes , and then, run this command:

    git rm -r --cached .
    

    This removes any changed files from the index(staging area), then just run:

    git add .
    

    Commit it:

    git commit -m ".gitignore is now working"
    

    To undo git rm --cached filename , use git add filename .


    If you are trying to ignore changes to a file that's already tracked in the repository (eg a dev.properties file that you would need to change for your local environment but you would never want to check in these changes) than what you want to do is:

    git update-index --assume-unchanged <file>
    

    If you wanna start tracking changes again

    git update-index --no-assume-unchanged <file>
    

    See git-update-index(1) Manual Page.

    Also have a look at the skip-worktree and no-skip-worktree options for update-index if you need this to persist past a git-reset (via)


    Update: Since people have been asking, here's a convenient (and updated since commented on below) alias for seeing which files are currently "ignored" (--assume-unchanged) in your local workspace

    $ git config --global alias.ignored = !git ls-files -v | grep "^[[:lower:]]"
    

    为了untrack已经被添加/初始化到存储库文件,即停止跟踪该文件,但不能从您的系统使用的删除: git rm --cached filename

    链接地址: http://www.djcxy.com/p/546.html

    上一篇: 如何修改git中的指定提交?

    下一篇: 忽略已经提交给Git存储库的文件