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

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


当前回答

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

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

https://github.com/settings/repositories

其他回答

我创建了一个bookmarklet脚本来使用NVRM的答案的方法来做到这一点。

要使用它,请创建一个新书签,为其命名,并将此脚本粘贴到URL字段中。在浏览一个回购时点击这个书签会弹出一个提醒,提醒的大小有兆字节和千字节。

javascript:(()=>{let url=new URL(document.location.href);if(url.origin!="https://github.com"){return}if(url.pathname=="/"){return}let p=url.pathname.slice(1,url.pathname.length);let parts=p.split('/');if(parts.length<2){return}let x=[parts[0],parts[1]].join('/');fetch(`https://api.github.com/repos/${x}`).then(r=>r.json()).then((b)=>alert(`${(b['size']/1000).toFixed(2)}mb (${b['size']}kb)`))})()

如果您拥有存储库,您可以通过打开帐户设置→存储库(https://github.com/settings/repositories)找到确切的大小,存储库的大小显示在其名称旁边。

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

注意:您可能是拥有多个存储库的组织的所有者,但在组织内的特定存储库中没有角色。默认情况下,即使您在自己拥有的组织中创建了存储库,也不会添加到repo,因此在设置/存储库中看不到该repo。所以把自己添加到存储库设置(https://github.com/org-name/repo-name/settings)中,在https://github.com/settings/repositories中看到它

有点hack:使用下载压缩文件选项,读取文件大小指示,然后取消它。

我不记得以zip格式下载是否有效,但无论如何,现在这样做只下载当前选择的没有历史记录的分支。

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

你所要做的就是去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') } )