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

时间:2011-12-27 15:50:37

标签: github

在你决定克隆它之前,有什么方法可以看到gitub上的git repo有多大?这似乎是一个非常明显/基本的统计数据,但我根本找不到如何在github上看到它。

12 个答案:

答案 0 :(得分:233)

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

在检索有关存储库的信息时,名为size的属性的值与整个存储库的大小(包括其所有历史记录)一起以千字节为单位。

例如,Git存储库的权重约为40Mb。返回的JSON有效内容的size属性值为40764

更新

大小确实以千字节为单位,基于服务器端裸存储库的磁盘使用情况。但是,为了避免使用大型网络的存储库浪费太多空间,GitHub依赖于 Git Alternates 。在此配置中,计算裸存储库的磁盘使用量不会考虑共享对象存储,因此通过API调用返回“不完整”值。

此信息由GitHub支持提供。

答案 1 :(得分:79)

如果您拥有回购,则可以通过打开Account Settings > Repositorieshttps://github.com/settings/repositories)找到确切的尺寸,并在其名称旁边显示回购协议尺寸。

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

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

我不记得下载zip是否有效,但无论如何,现在只下载当前选定的没有历史记录的分支。

答案 2 :(得分:62)

如果您使用Google Chrome浏览器,则可以安装GitHub Repository Size扩展程序。

enter image description here

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

答案 3 :(得分:15)

@larowlan很棒的示例代码。使用新的GitHub API V3,需要更新curl语句。此外,不再需要登录:

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

答案 4 :(得分:8)

用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 hub用户名替换YOURGITHUBUSERNAME(参见图)。 用repo所有者的git用户名替换OWNER 用repo名称替换REPO。

或者作为一个不错的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 repo的信息。

答案 5 :(得分:1)

从JavaScript开始,由于Github API已启用CORS:

fetch('https://api.github.com/repos/webdev23/source_control_sentry')
  .then(v => v.json()).then((function(v){
   console.log(v['size'] + "KB")
  })
)

答案 6 :(得分:1)

如果您想了解自己的存储库的大小。

您只需转到 GitHub 设置存储库,您就可以在浏览器中看到所有大小,无需额外工作。

https://github.com/settings/repositories

答案 7 :(得分:0)

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

#!/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

答案 8 :(得分:0)

您需要遵循github API,有关所有存储库的详细信息,请参阅文档here 它要求您以以下方式发出获取请求

获取/ repos /:owner /:repo

您需要替换两件事

  1. :所有者-拥有仓库的人的用户名
  2. :repo -存储库的名称

例如我的用户名 maheshmnj ,我拥有一个仓库 flutter-ui-nice 所以我的网址将是

https://api.github.com/repos/maheshmnj/flutter-ui-nice

在发出get请求时,您将充满一些json数据,并且可能在第78行上,您应该看到一个名为size的键,它将返回存储库的大小。

提示:与Json一起使用时,建议您添加一个格式化Json数据的插件,以使读取JSON变得容易。 install the plugin

答案 9 :(得分:0)

对于私有存储库,您需要从https://github.com/settings/tokens获取个人访问令牌。

然后使用以下curl命令获取详细信息(用[token],[owner]和[name]的值替换):

curl -u git:[token] https://api.github.com/repos/[owner]/[name] 2> /dev/null | grep size

如前所述,大小可能以MB或KB为单位。

答案 10 :(得分:0)

您可以使用Github API

这是Python示例:

import requests


if __name__ == '__main__':
    base_api_url = 'https://api.github.com/repos'
    git_repository_url = 'https://github.com/garysieling/wikipedia-categorization.git'

    github_username, repository_name = git_repository_url[:-4].split('/')[-2:]  # garysieling and wikipedia-categorization
    res = requests.get(f'{base_api_url}/{github_username}/{repository_name}')
    repository_size = res.json().get('size')
    print(repository_size)

答案 11 :(得分:0)

可以使用浏览器控制台并运行来实现这一点

fetch('https://api.github.com/repos/[USERNAME]/[REPO]')
  .then(v => v.json()).then((function(v){
   console.log(v['size'] + "KB")
  })
)

让我们考虑一个实际的例子。

假设有人想使用 Firefox 找到 this repo 的大小。

使用 Ctrl+Shift+K 打开控制台。

然后粘贴以下代码

fetch('https://api.github.com/repos/goncaloperes/TimeSeries')
  .then(v => v.json()).then((function(v){
   console.log(v['size'] + "KB")
  })
)

按下回车键,您将收到回购的大小,如下图所示。

enter image description here