git 如何使用类似 curl 的命令获取远程仓库的最后一次提交 ID?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19176359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:06:30  来源:igfitidea点击:

How to get the last commit ID of a remote repo using curl-like command?

gitgit-commit

提问by Manisha Eleperuma

I want to get the last commit ID of the remotegit repo.

我想获取远程git repo的最后一次提交 ID 。

The command git rev-parse HEADworks for a locally-cloned git repo, but I want to get it from the original GIT repo by a CURL command or so.

该命令git rev-parse HEAD适用于本地克隆的 git 存储库,但我想通过 CURL 命令左右从原始 GIT 存储库中获取它。

Eg: I want to get the last commit ID of the git URL https://git.appfactorypreview.wso2.com/history/apiapp.git/.

例如:我想获取 git URL https://git.appfactorypreview.wso2.com/history/apiapp.git/的最后一次提交 ID 。

How?

如何?

回答by Litmus

try this command

试试这个命令

git log --format="%H" -n 1

回答by John Szakmeister

I think what you want is this:

我想你想要的是这个:

git ls-remote $URL HEAD

If HEADdoesn't exist in the remote repository, then you likely want:

如果HEAD远程存储库中不存在,那么您可能需要:

git ls-remote $URL refs/heads/master

Note that in the first instance, HEADis going to point to the default branch to checkout in the repository. You need to be sure that's the branch you want, or just use the second form and specify the one you want (replace refs/heads/masterwith the name of the branch you want: refs/heads/BRANCH_NAME.

请注意,在第一个实例中,HEAD将指向默认分支以在存储库中签出。您需要确保这是您想要的分支,或者只使用第二种形式并指定您想要的一个(替换refs/heads/master为您想要的分支的名称:refs/heads/BRANCH_NAME.

回答by brunetton

Another way, without using git log:

另一种方式,不使用 git log:

git rev-parse HEAD

git rev-parse HEAD

回答by silvio

You can use git ls-remotefor this. Because I get a 'Unauthorized access for repository apiapp.git'I use as example torvalds linux-repo.

您可以git ls-remote为此使用。因为我得到了一个'Unauthorized access for repository apiapp.git'我用作示例 torvalds linux-repo。

$ git ls-remote --heads git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
6d15ee492809d38bd62237b6d0f6a81d4dd12d15        refs/heads/master

回答by codelovesme

Simplest way I use:

我使用的最简单的方法:

git rev-parse origin/develop

回答by mariotomo

my answer would not help the OP because he's not on github, but I think I would mention it anyway because it uses curl, or wget, as the OP requested.

我的回答对 OP 没有帮助,因为他不在 github 上,但我想我无论如何都会提到它,因为它按照 OP 的要求使用curl, or wget

wget -qO- http://api.github.com/repos/Ghini/ghini.desktop/commits/ghini-1.0

wget -qO- http://api.github.com/repos/Ghini/ghini.desktop/commits/ghini-1.0

Ghiniis my repo, ghini.desktopis my repository, ghini-1.0is the branch I'm interested in. Replace them to fit your case.

Ghini是我的回购,ghini.desktop是我的存储库,ghini-1.0是我感兴趣的分支。替换它们以适合您的情况。

the JSON answer is a dictionary, and the OP was interested in its shafield, but it contains a lot more information.

JSON 答案是一本字典,OP 对它的sha领域很感兴趣,但它包含更多信息。