Reputation: 949
By means of cloning I am able to find the HEAD of a git repository and using HEAD I can find the revision ID in GITHUB using following code in Egit:- ObjectId revId = repository.resolve(Constants.HEAD); How can I find this revision ID without cloning the whole repository by only knowing the url of my GITHub repository as cloning the whole repository takes time.Pls suggest.
Upvotes: 3
Views: 11196
Reputation: 593
You could get this information from the GitHub API.
The API provides an endpoint to get all commits for a repository. In your case,
you can just fetch the most recent commit on the branch in question. For
example, this curl request fetches the most recent commit from the master
branch of the rails/rails
repository.
curl "https://api.github.com/repos/rails/rails/commits?sha=master&per_page=1"
[
{
"sha": "c52a4ae565671e3a3b1513a285dc887102d5eb15",
"commit": {
"author": {
"name": "Santiago Pastorino",
"email": "[email protected]",
"date": "2013-09-03T15:18:41Z"
},
"committer": {
"name": "Santiago Pastorino",
"email": "[email protected]",
"date": "2013-09-03T15:18:41Z"
},
"message": "Revert \"Merge pull request #12085 from valk/master\"\n\nThis reverts commit 15455d76c8d33b3767a61e0cdd2de0ff592098ef, reversing\nchanges made to ffa56f73d5ae98fe0b8b6dd2ca6f0dffac9d9217.",
// ...
}
]
In this example, we see that c52a4ae565671e3a3b1513a285dc887102d5eb15
is the most recent commit. Note that we see the same info in the web UI:
Upvotes: 1
Reputation: 1330092
From any directory, you can use git ls-remote
:
C:\Users\VonC\>git ls-remote https://github.com/git/git master
e230c568c4b9a991e3175e5f65171a566fd8e39c refs/heads/master
4b5eac7f03f411f75087e0b6db23caa999624304 refs/remotes/github/master
4b5eac7f03f411f75087e0b6db23caa999624304 refs/remotes/origin/master
C:\Users\VonC\>git ls-remote https://github.com/git/git HEAD
e230c568c4b9a991e3175e5f65171a566fd8e39c HEAD
4b5eac7f03f411f75087e0b6db23caa999624304 refs/remotes/origin/HEAD
You can see that way the SHA1 of the refspecs including the ref you are interesting in.
The examples above list the SHA1 of refspecs including 'master
' or 'HEAD
'
You can see the HEAD
of the repo 'git' is 4b5eac7... and it corresponds to heads/master
(which means the HEAD of that remote repo is the master
branch)
No cloning was needed for that command to work.
Upvotes: 7
Reputation: 174477
Are you talking about the commit hash?
You can easily see it on the "Commits" page.
Example for AutoFixture: https://github.com/AutoFixture/AutoFixture/commits/master
As you can see, each commit has its hash on the right hand side. The hash for the HEAD of master is cdc59a9a4889504d882aaa47b222a0410174d917
. For HEAD^
it is ab05261e1d175d93f11ed37020f802933a20789c
and so on.
Upvotes: 3