查询最后一次提交到git repo而不克隆 [英] Query last commit to a git repo without cloning

查看:58
本文介绍了查询最后一次提交到git repo而不克隆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设并且仅当在最近的 n 小时内(例如24小时)内提交了对master的提交,我希望从URL中克隆一个大型git repo.我不想克隆它,因为对于这么大的仓库来说这是很费时的,我也不想克隆一次然后检查例如git status定期.

Suppose I wish to clone a large git repo from a URL, if and only if a commit was made to master within the last n (say 24) hours. I don't want to clone it, because that's rather time-consuming for such a large repo, nor do I wish to clone it once and then check e.g. git status periodically.

我希望能够告知克隆之前最后一次提交的时间.有没有办法在git中做到这一点?如果没有,我有什么选择?我知道我可以通过 git ls-remote

I want to be able to tell when the last commit was made prior to cloning. Is there a way of doing this in git? If not, what are my options? I know I can get the hash of the last commit via git ls-remote

推荐答案

一个选项可能是继续克隆存储库,但深度只有1.这应该可以非常快速地下载.

One option could be to go ahead and clone the repo, but only with a depth of 1. This should make for a very fast download.

然后,您可以检查主人的时间戳记.

Then, you could check the tip of master's timestamp.

示例:

git clone --depth 1 https://github.com/jquery/jquery.git jquery

有关更多信息,请参见文章

See this article for more information.

Git支持浅克隆"的概念,这是一个更用以下方法描述本地存储库的简洁有意义的方式克隆操作期间,历史记录被截断到特定深度.经过向clone命令(过程)提供--depth 1的参数将仅复制存储库中所有内容的最新版本.

Git supports the notion of a "shallow clone", which is a more succinctly meaningful way of describing a local repository with history truncated to a particular depth during the clone operation. By providing an argument of --depth 1 to the clone command, the process will copy only the latest revision of everything in the repository.

-

如果目标存储库位于GitHub上,则另一个选择是使用GitHub的REST API,如下所示:

Another option, if your target repo is on GitHub, would be to use GitHub's REST API like this:

GET /repos/:owner/:repo/commits/:sha

然后您可以解析响应以获取提交的时间戳.

You can then parse the response for the commit's timestamp.

更多信息: https://developer.github.com/v3/repos/commits/#get-a-single-commit

这篇关于查询最后一次提交到git repo而不克隆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆