在你决定克隆它之前,有没有办法看看GitHub上的Git存储库有多大?
这似乎是一个非常明显/基本的统计数据,但我根本找不到如何在GitHub上看到它。
在你决定克隆它之前,有没有办法看看GitHub上的Git存储库有多大?
这似乎是一个非常明显/基本的统计数据,但我根本找不到如何在GitHub上看到它。
当前回答
总结一下@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
其他回答
如果您使用谷歌Chrome浏览器,您可以安装GitHub存储库大小扩展。
回购地址:https://github.com/harshjv/github-repo-size
如果您拥有存储库,您可以通过打开帐户设置→存储库(https://github.com/settings/repositories)找到确切的大小,存储库的大小显示在其名称旁边。
如果您不拥有存储库,则可以对其进行分叉,然后在同一位置检查。
注意:您可能是拥有多个存储库的组织的所有者,但在组织内的特定存储库中没有角色。默认情况下,即使您在自己拥有的组织中创建了存储库,也不会添加到repo,因此在设置/存储库中看不到该repo。所以把自己添加到存储库设置(https://github.com/org-name/repo-name/settings)中,在https://github.com/settings/repositories中看到它
有点hack:使用下载压缩文件选项,读取文件大小指示,然后取消它。
我不记得以zip格式下载是否有效,但无论如何,现在这样做只下载当前选择的没有历史记录的分支。
@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:]'
在浏览器中,使用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') } )
总结一下@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