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

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


当前回答

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

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

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

例如,Git存储库的重量约为124 MB。返回的JSON有效负载的size属性的值为124283。

更新

大小实际上是根据服务器端裸存储库的磁盘使用情况以千字节表示的。然而,为了避免在拥有大型网络的存储库上浪费太多空间,GitHub依赖于Git Alternates。在此配置中,根据裸存储库计算磁盘使用情况并不考虑共享对象存储,因此通过API调用返回“不完整”的值。

此信息由GitHub支持提供。

其他回答

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

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

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

如果您试图找出您自己的存储库的大小。

你所要做的就是去GitHub设置存储库,你可以在浏览器中看到所有的大小,不需要额外的工作。

https://github.com/settings/repositories

总结一下@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

在浏览器中,使用JavaScript,因为Github API启用了CORS:

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