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

主宰稳场 提交于 2019-11-28 17:11:23

try this command

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

I think what you want is this:

git ls-remote $URL HEAD

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

git ls-remote $URL refs/heads/master

Note that in the first instance, HEAD is 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/master with the name of the branch you want: refs/heads/BRANCH_NAME.

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

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

Another way, without using git log:

git rev-parse HEAD

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.

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

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

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!