Is there a way to remove all ignored files from a git repo?

This question already has an answer here:

  • How to remove local (untracked) files from the current Git working tree? 31 answers

  • git clean -dfX
    

    git-clean - Remove untracked files from the working tree
    -d for removing directories
    -f remove forcefully
    -n Don't actually remove anything, just show what would be done.
    -X Remove only files ignored by Git. This may be useful to rebuild everything from scratch, but keep manually created files.


    There is a single command solution:

    git ls-files --ignored --exclude-standard | sed 's/.*/"&"/' | xargs git rm -r --cached
    

    What it does is:

  • List all ignored files
  • Handle paths with spaces to avoid failure
  • Call git rm -r --cached to remove all the ignored files from index (without removing them from your local machine)
  • 链接地址: http://www.djcxy.com/p/3270.html

    上一篇: 撤消更改

    下一篇: 有没有办法从git仓库中删除所有被忽略的文件?