早在过去,我就不小心将大量的Java工件(.war、.jar和.class)提交到了GitHub回购中。这导致了一个巨大的膨胀,其大小约为100兆。直到许多提交和分支合并之后,我才注意到。
幸运的是,在StackOverflow、GitHub和Git文档中无休止地拖网之后,有很多关于这方面的信息(谢谢大家!)最后,我成功地将以下脚本组合在一起:
#!/bin/bash
echo "Removing history for *.war, *.jar, *.class files"
echo "Starting size"
git count-objects -v
echo "Removing history for *.war, *.jar, *.class files"
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch *.war' --prune-empty --tag-name-filter cat -- --all
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch *.jar' --prune-empty --tag-name-filter cat -- --all
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch *.class' --prune-empty --tag-name-filter cat -- --all
echo "Purging refs and garbage collection"
# Purge the backups
rm -Rf .git/refs/original
# Force reflog to expire now (not in the default 30 days)
git reflog expire --expire=now --all
# Prune
git gc --prune=now
# Aggressive garbage collection
git gc --aggressive --prune=now
echo
echo "Ending size (size-pack shows new size in Kb)"
git count-objects -v
# Can't do this in the script - it needs a human to be sure
echo
echo "Now use this command to force the changes into your remote repo (origin)"
echo
echo git push --all origin --force这在当地非常有效,我的100 2Mb回购下降到了大约2Mb。然后我使用了
git push --all origin --force命令用本地更改覆盖GitHub回购中的所有分支。一切都很顺利。为了检查所有内容,我删除了本地回购并从GitHub中克隆。这个应该是2Mb,但又是100 2Mb。
那么,在这么多闲谈之后,我哪里出了问题?我怎样才能强迫GitHub使用我的本地回购及其清除历史?
编辑获取更多信息
GitHub回购不能被删除,因为它有很多关于它的附加信息(问题、维基、手表等)。对一个空的scratch回购执行这个脚本很好--克隆的回购是2Mb。
问题仍然是为什么它不工作与主要回购。
发布于 2012-10-16 19:37:12
这一切都是因为一个叉子
结果是,如果有人在GitHub上分叉了您的回购,那么他们会保留链接和对其中条目的引用。因此,除非每个拿叉子的人也在他们的回购上运行脚本,否则你的清除就不会起作用。
https://stackoverflow.com/questions/12873063
复制相似问题