Rod*_*igo 82 git git-rewrite-history
可能重复:
如何从Git中的提交历史中清除一个巨大的文件?
我做了一件蠢事.想象一下,我提交了一个100MB的文件.然后我看到这个并删除此文件并再次提交.这是删除文件的正常过程.
但现在副作用是我的历史很重,因为它保存了这个大文件(我相信这就是为什么它很重).我只使用本地git,所以我不在任何服务器同步.
如何最终删除此文件并节省磁盘空间?
Leo*_*Leo 156
您可以使用git filter-branch命令执行此操作,如下所示:
git filter-branch --tree-filter 'rm -rf path/to/your/file' HEAD
Run Code Online (Sandbox Code Playgroud)
您可以在此处找到更多文档http://dalibornasevic.com/posts/2-permanently-remove-files-and-folders-from-a-git-repository
top*_*pek 17
你可以从David Underhill这个伟大的脚本中删除git存储库中的文件:
#!/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
Run Code Online (Sandbox Code Playgroud)