在克隆之前查看github回购的大小?

在你决定克隆之前,有没有办法看到Git上有多大的git repo? 这似乎是一个非常明显的/基本的统计,但我不能find如何在Github上看到它。

有一种方法可以通过GitHub API访问这些信息。

  • 语法/repos/:user/:repo [GET]
  • 例如: https //api.github.com/repos/git/git

在检索有关存储库的信息时,名为size的属性将以整个存储库(包括其所有历史logging)的大小(以千字节为单位)进行评估。

例如,Git仓库重约40Mb。 返回的JSON负载的size属性值为40764

更新:

这个大小实际上是以基于服务器端裸机存储库的磁盘使用量的千字节表示的。 但是,为了避免浪费太多的空间与大型networking库,GitHub依赖于Git Alternates 。 在此configuration中,计算裸仓库的磁盘使用情况不会计入共享对象库,因此将通过API调用返回“不完整”值。

这些信息由GitHub支持提供。

如果您拥有回购股票,您可以通过打开您的Account Settings > Repositoriesfind确切的大小,回购大小显示在其指定旁边。

如果您不拥有该存储库,则可以将其分叉,然后在同一个地方进行检查。

有点hacky:使用download as a zip file选项,读取指定的文件大小,然后取消它。

我不记得是否以压缩格式下载过,但无论如何, 现在只下载没有历史logging的当前select的分支。

如果您使用Google Chrome浏览器,则可以安装GitHub存储库大小扩展。

在这里输入图像说明

在这里回复: https : //github.com/harshjv/github-repo-size

@larowlan伟大的示例代码。 使用新的GitHub API V3,需要更新curl语句。 另外,login不再是必需的:

 curl https://api.github.com/repos/$2/$3 2> /dev/null | grep size | tr -dc '[:digit:]' 

用curl(sudo apt-get curl)和json pretty(sudo gem install jsonpretty json)来做到这一点。

 curl -u "YOURGITHUBUSERNAME" http://github.com/api/v2/json/repos/show/OWNER/REPO | jsonpretty 

用你的git中心用户名replaceYOURGITHUBUSERNAME(去图)。 用仓库所有者的git用户名replaceOWNER用仓库名称replaceREPO。

或者作为一个不错的bash脚本(将其粘贴到名为gitrepo-info的文件中)

 #!/bin/bash if [ $# -ne 3 ] then echo "Usage: gitrepo-info <username> <owner> <repo>" exit 65 fi curl -u "$1" http://github.com/api/v2/json/repos/show/$2/$3|jsonpretty 

像这样使用

 gitrepo-info larowlan pisi reel 

这将给我在github上的pisi / reel回购信息。

总结@larowlan,@VMTrooper和@vahid chakoshy解决scheme:

 #!/usr/bin/env bash if [ "$#" -eq 2 ]; then echo "$(echo "scale=2; $(curl https://api.github.com/repos/$1/$2 2>/dev/null \ | grep size | head -1 | tr -dc '[:digit:]') / 1024" | bc)MB" elif [ "$#" -eq 3 ] && [ "$1" == "-z" ]; then # For some reason Content-Length header is returned only on second try curl -I https://codeload.github.com/$2/$3/zip/master &>/dev/null echo "$(echo "scale=2; $(curl -I https://codeload.github.com/$2/$3/zip/master \ 2>/dev/null | grep Content-Length | cut -d' ' -f2 | tr -d '\r') / 1024 / 1024" \ | bc)MB" else printf "Usage: $(basename $0) [-z] OWNER REPO\n\n" printf "Get github repository size or, optionally [-z], the size of the zipped\n" printf "master branch (`Download ZIP` link on repo page).\n" exit 1 fi