如何从远程git存储库获取最新提交的SHA? [英] How to get SHA of the latest commit from remote git repository?

查看:908
本文介绍了如何从远程git存储库获取最新提交的SHA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何从外部获取给定分支的最新SHA git存储库?



如果你在git你可以这样做:

  git log origin / branch_X |头-1 

然而,我不在git仓库中,我想避免必须 clone 一个存储库,以获取标签/分支的最新SHA。是否有一个聪明的方法来做到这一点?

解决方案

如果您想检查远程存储库中给定分支的SHA-1, 您的答案是正确的:

  $ git ls-remote< URL> 

然而,如果您使用的是相同的文件系统更简单的解决方案(不需要从输出中提取SHA-1)简单地说就是:

  $ git --git-dir = / path / to / repo / .git rev-parse origin / branch_X 

请参阅 git(1)手册页用于描述' - git-dir '选项。

Does anyone know how to get the latest SHA of a given branch from outside a git repository?

If you are inside a git repository, you can do:

git log origin/branch_X | head -1

However, I am not inside a git repository, and I would like to avoid having to clone a repository just to get the latest SHA of a tag/branch. Is there a clever way of doing this?

解决方案

If you want to check SHA-1 of given branch in remote repository, then your answer is correct:

$ git ls-remote <URL>

However if you are on the same filesystem simpler solution (not requiring to extract SHA-1 from output) would be simply:

$ git --git-dir=/path/to/repo/.git rev-parse origin/branch_X

See git(1) manpage for description of '--git-dir' option.

这篇关于如何从远程git存储库获取最新提交的SHA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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