简体   繁体   中英

How do you remove certain files from all commits in a Git repo?

我在Git中的很多提交中都有很多delta文件(。*〜),我想从所有提交中删除所有文件。

Remove from all the commits looks like using git filter-branch :

git filter-branch --index-filter 'git rm --cached --ignore-unmatch .*~' HEAD

The GitHub help page has a more complete command:

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch .*~'  --prune-empty --tag-name-filter cat -- --all

With (as mentioned in this blog post ):

  • --index-filter which is similar to --tree-filter but does not check the tree, and it goes much faster.
  • --ignore-unmatch parameter, used to ignore nonexistent files.

That would rewrite the history of your repo, though.
That means any collaborators who would already have cloned said repo would need to reset his/her local clone to the new history of your repo once you git push --force it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM