简体   繁体   English

如何在不克隆整个存储库的情况下显示远程git存储库的master分支的修订日期?

[英]How can I show the revision date of a remote git repository's master branch, without cloning the whole repository?

I need to know the date and time of the latest revision of the master branch on a remote repository. 我需要知道远程存储库上master分支的最新修订的日期和时间。 I've got git installed locally, and I know the HTTPS clone URL for the git repo, which is hosted on GitHub. 我已经在本地安装了git,而且我知道git repo的HTTPS克隆URL,该URL托管在GitHub上。 I know that if I had the repo cloned, I could do git show --format="%ci %cr" master | head -n 1 我知道如果克隆了仓库,我可以做git show --format="%ci %cr" master | head -n 1 git show --format="%ci %cr" master | head -n 1 , but I need a command that will run quickly, and not leave any sizeable data behind; git show --format="%ci %cr" master | head -n 1 ,但是我需要一个可以快速运行的命令,并且不会留下任何可观的数据; Cloning a 200 MB repo won't work. 克隆200 MB的存储库将不起作用。

How can I show the revision date of a remote GitHub repository's master branch, without cloning the whole repository? 如何在不克隆整个存储库的情况下显示远程GitHub存储库的master分支的修订日期?

I don't think you can do this strictly with Git (ie in a way that would work with all Git remotes). 我认为您不能使用Git严格执行此操作(即,以与所有 Git遥控器均兼容的方式)。 But there is a solution using GitHub's GET /repos/:owner/:repo/branches/:branch endpoint , eg 但是有一个使用GitHub的GET /repos/:owner/:repo/branches/:branch端点的解决方案 ,例如

curl https://api.github.com/repos/github/git-lfs/branches/master
# {
#   "name": "master",
#   "commit": {
#     "sha": "df4be34fff5d9c70f5d8b897bbe23fa809776b6a",
#     "commit": {
#       "author": {
#         "name": "risk danger olson",
#         "email": "technoweenie@gmail.com",
#         "date": "2015-08-04T21:24:00Z"
#       },
#       "committer": {
#         "name": "risk danger olson",
#         "email": "technoweenie@gmail.com",
#         "date": "2015-08-04T21:24:00Z"
#       },
#       ...

Use your favourite JSON library to extract the commit/commit/author/date and / or commit/commit/committer/date nodes from the response. 使用您喜欢的JSON库从响应中提取commit/commit/author/date和/或commit/commit/committer/date节点。 The command-line tool jq might be helpful: 命令行工具jq可能会有所帮助:

curl https://api.github.com/repos/github/git-lfs/branches/master \
    | jq .commit.commit.author.date,.commit.commit.committer.date
# "2015-08-04T21:24:00Z"
# "2015-08-04T21:24:00Z"

For private repositories you'll have to authenticate . 对于私有存储库,您必须进行身份验证

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Git:如何将其他存储库的远程主分支合并到本地主分支而不污染它 - Git: how to merge other repository's remote master branch into local master without contaminating it 如何在GITHUB中无需克隆的情况下查找Git存储库的修订版ID - How to find revision ID of a Git repository without cloning in GITHUB 如何跟踪新的远程存储库的master分支? - How can I track the master branch of a new remote repository? 如何删除本地git存储库中的远程分支? - How can I delete a remote branch in a local git repository? 如何重置整个Git存储库,而不只是重置“ Master”分支,以匹配Remote? - How to reset the entire Git repository, and not only the “Master” branch, to match Remote? 标记远程git存储库而不克隆它 - Tag a remote git repository without cloning it 无需克隆即可访问远程存储库的 Git API - Git API to access a remote repository without cloning it 如何在不下载整个存储库的情况下“拉”一个 git 数据库 - How can I "pull" a git database without downloading the whole repository GIT提取或克隆存储库只能获得Master分支 - GIT pulling or cloning repository only gets Master branch Git:我忘记创建分支 master,如果我的存储库已经有另一个分支,我该如何创建它? - Git: i forgot create branch master, how i can create it if my repository already has another branch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM