git-如何使用类似curl的命令获取远程仓库的最后提交ID?
我想获取远程git仓库的最后提交ID。
命令git rev-parse HEAD
适用于本地克隆的git repo,但是我想通过CURL命令从原始GIT repo中获取它。
例如:我想获取git URL的最后提交ID [https://git.appfactorypreview.wso2.com/history/apiapp.git/。]
怎么样?
Manisha Eleperuma asked 2020-06-27T01:23:41Z
6个解决方案
81 votes
试试这个命令
git log --format="%H" -n 1
30 votes
我认为您想要的是:
git ls-remote $URL HEAD
如果远程存储库中不存在HEAD
,则您可能需要:
git ls-remote $URL refs/heads/master
请注意,首先,HEAD
将指向默认分支以在存储库中检出。 您需要确保这是您想要的分支,或者仅使用第二种形式并指定您想要的分支(将refs/heads/master
替换为您想要的分支的名称:refs/heads/BRANCH_NAME
。
13 votes
您可以为此使用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
11 votes
另一种方法,不使用git log:
git rev-parse HEAD
1 votes
我的回答不会对OP有所帮助,因为他不在github上,但是我想还是要提一下,因为它按照OP的要求使用了sha
或ghini.desktop
。
sha
sha
是我的存储库,ghini.desktop
是我的存储库,ghini-1.0
是我感兴趣的分支。请替换它们以适合您的情况。
JSON答案是一个字典,OP对它的sha
字段很感兴趣,但是它包含很多信息。
0 votes
我使用的最简单方法:
git rev-parse origin/develop