在你决定克隆它之前,有没有办法看看GitHub上的Git存储库有多大?

这似乎是一个非常明显/基本的统计数据,但我根本找不到如何在GitHub上看到它。


当前回答

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

回购地址:https://github.com/harshjv/github-repo-size

其他回答

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

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

用你的GitHub用户名替换YOURGITHUBUSERNAME。

将OWNER替换为存储库所有者的Git用户名。 将REPOSITORY替换为存储库名称。

或者作为一个漂亮的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存储库的信息。

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

回购地址:https://github.com/harshjv/github-repo-size

你可以使用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)

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

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

例如:

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

返回931668 (KB),几乎是GB。

私有回购需要身份验证。一种方法是使用GitHub个人访问令牌:

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

对于私有存储库,您需要从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。