是否可以远程计算 git 存储库的对象和大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2882620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to remote count object and size of git repository?
提问by dfens
Assume that somewhere in the web exists public git repository. I want to clone it but firstly i need to be sure what is size of it (how much objects & kbytes like in git count-objects
)
假设网络中的某个地方存在公共 git 存储库。我想克隆它,但首先我需要确定它的大小(有多少对象和千字节git count-objects
)
Is there a way to do it?
有没有办法做到这一点?
采纳答案by Cascabel
One little kludge you could use would be the following:
您可以使用的一个小杂物如下:
mkdir repo-name
cd repo-name
git init
git remote add origin <URL of remote>
git fetch origin
git fetch
displays feedback along these lines:
git fetch
显示以下方面的反馈:
remote: Counting objects: 95815, done.
remote: Compressing objects: 100% (25006/25006), done.
remote: Total 95815 (delta 69568), reused 95445 (delta 69317)
Receiving objects: 100% (95815/95815), 18.48 MiB | 16.84 MiB/s, done.
...
The steps on the remote end generally happen pretty fast; it's the receiving step that can be time-consuming. It doesn't actually show the total size, but you can certainly watch it for a second, and if you see "1% ... 23.75 GiB" you know you're in trouble, and you can cancel it.
远程端的步骤通常发生得很快;接收步骤可能很耗时。它实际上并未显示总大小,但您当然可以观看一秒钟,如果您看到“1% ... 23.75 GiB”,您就知道您遇到了麻烦,您可以取消它。
回答by ken
For github repository, it now offer API to check file size. It works!
对于 github 存储库,它现在提供 API 来检查文件大小。有用!
This link: see-the-size-of-a-github-repo-before-cloning-itgave the answer
这个链接:see-the-the-the-size-of-a-github-repo-before-cloning-它给出了答案
Command: (answer from @VMTrooper)
命令:(来自@VMtrooper 的回答)
curl https://api.github.com/repos// | grep size
Example:
例子:
curl https://api.github.com/repos/Marijnh/CodeMirror | grep size
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 5005 100 5005 0 0 2656 0 0:00:01 0:00:01 --:--:-- 2779
"size": 28589,
回答by Bigwave
回答by Xentac
I think there are a couple problems with this question: git count-objects
doesn't truly represent the size of a repository (even git count-object -v
doesn't really); if you're using anything other than the dumb http transport, a
new pack will be created for your clone when you make it; and (as VonC pointed
out) anything you do to analyze a remote repo won't take into account the
working copy size.
我认为这个问题有几个问题:git count-objects
并不能真正代表存储库的大小(甚至git count-object -v
不是真的);如果您使用的不是笨拙的 http 传输,那么当您制作它时,将为您的克隆创建一个新包;并且(正如 VonC 指出的那样)您为分析远程仓库所做的任何事情都不会考虑工作副本的大小。
That being said, if they are using the dumb http transport (github, for example, is not), you could write a shell script that used curl to query the sizes of all the objects and packs. That might get you closer, but it's making more http requests that you'll just have to make again to actually do the clone.
话虽如此,如果他们使用愚蠢的 http 传输(例如 github,不是),您可以编写一个 shell 脚本,使用 curl 来查询所有对象和包的大小。这可能会让您更接近,但它会发出更多的 http 请求,您只需再次发出这些请求即可实际执行克隆。
It is possible to figure out what git-fetch
would send across the wire (to a
smart http transport) and send that to analyze the results, but it's not really
a nice thing to do. Essentially you're asking the target server to pack up
results that you're just going to download and throw away, so that you can
download them again to save them.
可以弄清楚什么git-fetch
会通过网络发送(到智能 http 传输)并发送它来分析结果,但这并不是一件好事。本质上,您是在要求目标服务器打包您要下载并丢弃的结果,以便您可以再次下载它们以保存它们。
Something like these steps can be used to this effect:
类似这些步骤的东西可以用来达到这个效果:
url=https://github.com/gitster/git.git
git ls-remote $url |
grep '[[:space:]]\(HEAD\|refs/heads/master\|refs/tags\)' |
grep -v '\^{}$' | awk '{print "0032want " }' > binarydata
echo 00000009done >> binarydata
curl -s -X POST --data-binary @binarydata \
-H "Content-Type: application/x-git-upload-pack-request" \
-H "Accept-Encoding: deflate, gzip" \
-H "Accept: application/x-git-upload-pack-result" \
-A "git/1.7.9" $url/git-upload-pack | wc -c
At the end of all of this, the remote server will have packed up master/HEAD and all the tags for you and you will have downloaded the entire pack file just to see how big it will be when you download it during your clone.
在所有这一切结束时,远程服务器将为您打包 master/HEAD 和所有标签,您将下载整个包文件,只是为了查看在克隆期间下载它时的大小。
When you finally do a clone, the working copy will be created as well, so the entire directory will be larger than these commands spit out, but the pack file generally is the largest part of a working copy with any significant history.
当您最终进行克隆时,也会创建工作副本,因此整个目录将比这些命令输出的要大,但包文件通常是具有任何重要历史记录的工作副本的最大部分。
回答by VonC
Not that I know of:
Git is not a server, there is nothing by default listening to a request (unless you activate a gitweb, or a gitolite layer)
And the command "git remote ...
" deals with the localcopy (fetched) of a remote repo.
不是我所知道的:
Git 不是服务器,默认情况下没有任何内容侦听请求(除非您激活 gitweb 或 gitolite 层)
并且命令“ git remote ...
”处理远程存储库的本地副本(获取) .
So unless you fetch something, or clone --bare
a remote repo, you won't have an idea of its size.
And that does not include the size of the working directory, once checked out.
因此,除非您获取某些东西或clone --bare
远程存储库,否则您不会知道它的大小。
一旦签出,这不包括工作目录的大小。