如本SO回答所述,git gc
实际上可以增加回购的大小!
另请参阅此线程
现在git具有一种安全机制,可以在运行' ' 时不立即删除未引用的对象git gc
。
默认情况下,未引用的对象会保留2周。这是为了使您能够轻松恢复意外删除的分支或提交,或者避免git gc
在并行运行的' '进程中删除正在创建但尚未引用的刚刚创建的对象的竞争。
因此,为了给已打包但未引用的对象留出宽限期,重新打包过程会将那些未引用的对象从包中推送到它们的松散形式,以便可以对其进行老化并最终对其进行修剪。
成为非引用的对象通常并不多。有404855个未引用的对象很多,而通过克隆首先将那些对象发送给这些对象是愚蠢的,并且完全浪费了网络带宽。
无论如何...要解决您的问题,您只需要git gc
使用--prune=now
参数运行' ' 以禁用该宽限期并立即清除那些未引用的对象(仅在没有其他git活动同时发生时才是安全的)易于确保在工作站上)。
顺便说一句,使用' git gc --aggressive
'和更高版本的git版本(或' git repack -a -f -d --window=250 --depth=250
')
在同一个线程中提到:
git config pack.deltaCacheSize 1
这会将增量缓存大小限制为一个字节(有效地将其禁用),而不是默认值0,这意味着无限制。这样,我就可以git repack
在具有4GB RAM和4个线程(这是四核)的x86-64系统上使用上述命令重新打包该存储库。但是,常驻内存使用量已增长到近3.3GB。
如果您的计算机是SMP并且没有足够的RAM,则可以将线程数减少到一个:
git config pack.threads 1
此外,您还可以通过--window-memory argument
将“ git repack
” 限制为内存使用。
例如,使用--window-memory=128M
应该在增量搜索内存使用上保持合理的上限,尽管如果存储库包含大量大文件,则这可能会导致最佳增量匹配变差。
在分支过滤器的前面,您可以(谨慎)考虑此脚本
#!/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