清理 git 服务器上的大文件
Clean up large files on git server
有人不小心将一些大型(多 GB)二进制文件提交到我的自托管 gitlab 存储库,现在每次有人试图从存储库中提取时,服务器都会受到重创。
我尝试通过强制推送删除对文件的任何引用,但它似乎仍然影响服务器。有没有办法强制gitlab服务器摆脱它?
我阅读了一些像 filter-branch 这样的东西,但我不确定这会对裸仓库有什么影响,或者我什至如何在我不再引用的提交中使用它。
更新:作为参考,这些类型的消息出现在 gitlab VM 的控制台上:
[ 5099.922896] Out of memory: kill process 6200 (git-upload-pack) score 1053982 or a child
[ 5099.922908] Killed process 6202 (git)
[ 5099.930796] Out of memory: kill process 6200 (git-upload-pack) score 360394 or a child
[ 5099.930807] Killed process 6203 (git)
[ 5099.938875] Out of memory: kill process 6200 (git-upload-pack) score 360394 or a child
[ 5099.938886] Killed process 6203 (git)
[ 5099.951163] Out of memory: kill process 6139 (git-upload-pack) score 324327 or a child
[ 5099.951174] Killed process 6151 (git)
为此,您将打破从该提交推送的任何存储库的历史记录。你必须告诉他们。
您需要的是重新设置远程存储库的基线并删除此提交。
首先,在您的存储库中变基。
git rebase -i problematicCommit~1
这将打开您的默认编辑器。删除提交有问题的行。保存文件并关闭它。
删除远程存储库中的分支。
git push origin :nameOfTheBranch
查看分支名称前的点。
最后,在远程重新创建分支。
git push origin nameOfTheBranch
这会在没有冲突提交的情况下在远程重新生成分支,新的克隆将再次快速。
现在,如果您仍然注意到您的存储库运行缓慢。您可以删除它拥有的未跟踪对象(例如带有这个大文件的对象)。
首先,删除所有可能指向旧提交的标签和分支。这很重要,因为为了能够擦除旧的提交,它们必须未被跟踪。
然后,按照 VonC 评论 Whosebug。com/a/28720432/6309 - 在您的存储库和远程中执行:
git gc
git repack -Ad
git prune
因为服务器端的 OP Karl confirms , running BFG repo cleaner(直接在裸仓库中)足以删除大型二进制文件。
如果您按照(如“”中所述):
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
还有 ("git gc --aggressive
vs git repack
"):
git gc
git repack -Ad # kills in-pack garbage
git prune # kills loose garbage
你最终应该得到一个更精简、更小的裸仓库。
遇到了同样的问题,解决它的过程非常复杂。
我们 运行 社区维护 sameersbn/gitlab 11.4.5 Docker容器。我不想在那里安装 bfg
,而是选择在本地执行更改。
# Install the bfg tool, ex. on MacOS via homebrew
brew install bfg
# Clone repo locally
cd ~/Development
git clone --mirror ssh://git@server.com:22/some/dir/myrepo.git
# Clean the repo
bfg --delete-files \*.pdf myrepo.git
cd myrepo.git
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
# Upload to container-host, e.g. via FileZilla
# Connect to the container-host via ssh
# Rename the original directory in the container, to have a backup
docker exec -it gitlab /bin/bash
mv /home/git/data/repositories/some/dir/myrepo.git /home/git/data/repositories/some/dir/myrepo.git.mybackup
exit
# Copy from container-host into container
docker cp /root/Documents/myrepo.git gitlab:/home/git/data/repositories/some/dir/myrepo.git
# Fix permissions in container
docker exec -it gitlab /bin/bash
cd /home/git/data/repositories/some/dir/myrepo.git
find . -type f -print0 | xargs -0 chown git:git
chown -R git:git /home/git/data/repositories/some/dir/myrepo.git
chmod 770 /home/git/data/repositories/some/dir/myrepo.git
# Re-create the "hooks" subdir with some symlinks in the repo
cd /home/git/gitlab/bin
./rake gitlab:shell:create_hooks
# Clear Redis cache (unclear if needed)
./rake cache:clear
exit
# Clone the changed repo locally again, also tell everyone who got a copy to clone again (history is broken now)
# Then do a commit to the repo, to hit the hook and trigger a size recheck
有人不小心将一些大型(多 GB)二进制文件提交到我的自托管 gitlab 存储库,现在每次有人试图从存储库中提取时,服务器都会受到重创。
我尝试通过强制推送删除对文件的任何引用,但它似乎仍然影响服务器。有没有办法强制gitlab服务器摆脱它?
我阅读了一些像 filter-branch 这样的东西,但我不确定这会对裸仓库有什么影响,或者我什至如何在我不再引用的提交中使用它。
更新:作为参考,这些类型的消息出现在 gitlab VM 的控制台上:
[ 5099.922896] Out of memory: kill process 6200 (git-upload-pack) score 1053982 or a child
[ 5099.922908] Killed process 6202 (git)
[ 5099.930796] Out of memory: kill process 6200 (git-upload-pack) score 360394 or a child
[ 5099.930807] Killed process 6203 (git)
[ 5099.938875] Out of memory: kill process 6200 (git-upload-pack) score 360394 or a child
[ 5099.938886] Killed process 6203 (git)
[ 5099.951163] Out of memory: kill process 6139 (git-upload-pack) score 324327 or a child
[ 5099.951174] Killed process 6151 (git)
为此,您将打破从该提交推送的任何存储库的历史记录。你必须告诉他们。
您需要的是重新设置远程存储库的基线并删除此提交。
首先,在您的存储库中变基。
git rebase -i problematicCommit~1
这将打开您的默认编辑器。删除提交有问题的行。保存文件并关闭它。
删除远程存储库中的分支。
git push origin :nameOfTheBranch
查看分支名称前的点。
最后,在远程重新创建分支。
git push origin nameOfTheBranch
这会在没有冲突提交的情况下在远程重新生成分支,新的克隆将再次快速。
现在,如果您仍然注意到您的存储库运行缓慢。您可以删除它拥有的未跟踪对象(例如带有这个大文件的对象)。
首先,删除所有可能指向旧提交的标签和分支。这很重要,因为为了能够擦除旧的提交,它们必须未被跟踪。
然后,按照 VonC 评论 Whosebug。com/a/28720432/6309 - 在您的存储库和远程中执行:
git gc
git repack -Ad
git prune
因为服务器端的 OP Karl confirms
如果您按照(如“
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
还有 ("git gc --aggressive
vs git repack
"):
git gc
git repack -Ad # kills in-pack garbage
git prune # kills loose garbage
你最终应该得到一个更精简、更小的裸仓库。
遇到了同样的问题,解决它的过程非常复杂。
我们 运行 社区维护 sameersbn/gitlab 11.4.5 Docker容器。我不想在那里安装 bfg
,而是选择在本地执行更改。
# Install the bfg tool, ex. on MacOS via homebrew
brew install bfg
# Clone repo locally
cd ~/Development
git clone --mirror ssh://git@server.com:22/some/dir/myrepo.git
# Clean the repo
bfg --delete-files \*.pdf myrepo.git
cd myrepo.git
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
# Upload to container-host, e.g. via FileZilla
# Connect to the container-host via ssh
# Rename the original directory in the container, to have a backup
docker exec -it gitlab /bin/bash
mv /home/git/data/repositories/some/dir/myrepo.git /home/git/data/repositories/some/dir/myrepo.git.mybackup
exit
# Copy from container-host into container
docker cp /root/Documents/myrepo.git gitlab:/home/git/data/repositories/some/dir/myrepo.git
# Fix permissions in container
docker exec -it gitlab /bin/bash
cd /home/git/data/repositories/some/dir/myrepo.git
find . -type f -print0 | xargs -0 chown git:git
chown -R git:git /home/git/data/repositories/some/dir/myrepo.git
chmod 770 /home/git/data/repositories/some/dir/myrepo.git
# Re-create the "hooks" subdir with some symlinks in the repo
cd /home/git/gitlab/bin
./rake gitlab:shell:create_hooks
# Clear Redis cache (unclear if needed)
./rake cache:clear
exit
# Clone the changed repo locally again, also tell everyone who got a copy to clone again (history is broken now)
# Then do a commit to the repo, to hit the hook and trigger a size recheck