How do I remove a big file wrongly committed in git
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
How to purge a huge file from commits history in Git?
号
我做了件蠢事。假设我提交了一个100MB文件。然后我看到这个,删除这个文件并再次提交。这是删除文件的正常过程。
但是现在副作用是我的历史很重,因为它保存了这个大文件(我相信这就是为什么它很重)。我只使用本地Git,所以不在任何服务器中同步。
如何确定删除此文件并节省磁盘空间?
您可以使用git
1 | git filter-branch --tree-filter 'rm -rf path/to/your/file' HEAD |
号
您可以在以下位置找到更多文档:http://dalibornasevic.com/posts/2-permanently-remove-files-and-folders-from-a-git-repository
你要找的命令是
- http://dalibornasevic.com/posts/2-permanently-remove-files-and-folders-from-a-git-repository(永久删除文件和文件夹)
您可以从David Underhill获取这个伟大的脚本,从Git存储库中删除该文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #!/bin/bash set -o errexit # Author: David Underhill # Script to permanently delete files/folders from your git repository. To use # it, cd to your repository's root and then run the script with a list of paths # you want to delete, e.g., git-delete-history path1 path2 if [ $# -eq 0 ]; then exit 0 fi # make sure we're at the root of git repo if [ ! -d .git ]; then echo"Error: must run this script from the root of a git repository" exit 1 fi # remove all paths passed as arguments from the history of the repo files=$@ git filter-branch --index-filter"git rm -rf --cached --ignore-unmatch $files" HEAD # remove the temporary history git-filter-branch otherwise leaves behind for a long time rm -rf .git/refs/original/ && git reflog expire --all && git gc --aggressive --prune |