git消耗更少磁盘空间的最佳方法是什么?
我在我的存储库上使用git-gc(这确实有帮助,特别是如果自克隆以来已经有很多提交)但我想建议是否有任何其他命令来缩小git使用的磁盘空间.
谢谢
Jak*_*ski 46
我可以提供一些建议:
删除不再使用的分支.他们可以固定一些您不使用但永远不会使用的提交.但请注意不要删除以后需要的分支(可能用于审核或比较失败的工作量).先备份.
检查您是否错误地提交了一些大型二进制文件(可能是某些生成的文件).如果你有,你可以使用"git filter-branch"从历史中清除它......好吧,如果你没有共享存储库,或者值得加重其他贡献者来重写历史记录.再次:先备份.
你可以更积极地修剪,丢弃一些安全,使用git gc --prune=now
或低级别git prune
.但请注意,您不要删除压缩后需要一分钟的安全和备份(如reflog).
也许扩大存储库的是工作目录中的一些未跟踪文件."make clean"或"git clean"可能有所帮助(但请注意不要删除一些重要文件).
所有这些建议中最安全的:你可以尝试更积极地使用--depth
和使用--window
低级别的选项git-repack
.另见Pieter de Bie在2008年6月6日的DVCS比较博客上发表的Git Repack Parameters博客文章.或者" git gc --aggressive
".
adl*_*adl 21
根据您对存储库的操作,您还可以考虑使用以下git clone
选项:
--depth <depth>
Create a shallow clone with a history truncated to the specified
number of revisions. A shallow repository has a number of
limitations (you cannot clone or fetch from it, nor push from nor
into it), but is adequate if you are only interested in the recent
history of a large project with a long history, and would want to
send in fixes as patches.
Run Code Online (Sandbox Code Playgroud)
Git clone现在有一个--single-branch选项,允许你签出一个分支而不需要拉入其他分支的git历史记录.如果git占用大量磁盘空间,因为你有很多分支,你可以删除当前的签出并使用此选项重新克隆repo以重新获得一些磁盘空间.例如:
cd ../
rm -rf ./project
git clone -b master --single-branch git@github.com:username/project.git
Run Code Online (Sandbox Code Playgroud)
此外,如果您当前的主服务器具有较长的历史记录且您没有任何需要合并回主服务器的未完成分支,则可以从主服务器创建存档分支并创建一个没有git历史记录的新的孤立主服务器:
git checkout -b master_archive_07162013 # create and switch to the archive branch
git push origin master_archive_07162013 # push the archive branch to the remote and track it
git branch -D master # delete local master
git push --delete origin master # delete remote master
git remote prune origin # delete the remote tracking branch
git checkout --orphan master # create a new master branch with no history
git commit -m "initial commit" # re-establish the files in the repo
git push origin master # push the new master to the remote
Run Code Online (Sandbox Code Playgroud)
新的主分支树将不与旧的归档主分支相关联,因此只有在您真正归档分支时才这样做.
如果您将主分支存档,然后使用单分支存档git clone master,则结帐应该要小得多.
如果您不需要在本地保留所有提交历史记录,则可以使用浅克隆:
git clone --depth=1 [url_of_repo]
Run Code Online (Sandbox Code Playgroud)
如果我只对最新的文件集而不是历史记录感兴趣,我在克隆 GitHub 项目时经常使用此功能。
显然,浅克隆不支持获取和推送,但我已经能够使用它成功地推送和拉取对 GitHub 存储库的更改,因此它也可能适用于您的情况。(但是毫无疑问,如果您想合并分支但历史上没有基础提交,您会遇到困难。)
我认为从上面所示的新克隆开始更容易,但其他人已经展示了如何修剪现有的本地存储库。
归档时间: |
|
查看次数: |
23687 次 |
最近记录: |