1

I'm using git ls-remote to get commit hashes of branches in a repository of which I don't have a clone.

git ls-remote ssh://gitosis@myServer/myRepo.git master

I'm interested being about specify a commit like master~ and use git ls-remote to figure out what it's commit hash is.

Does Git support this?

ajwood
  • 18,227
  • 15
  • 61
  • 104

2 Answers2

1

Does Git support this?

No, as I explained in "Show git logs for range of commits on remote server?"

it works on ref patterns (head, tags, branches, ...), not with revs

You would need to fetch first, in order to check origin/master~.


Intended use:

A custom, perhaps hackish, application.
It's a mechanism for users to issue requests to the system for building and installing specific versions of software.
It supports build_request SomeProject someBranch.
For completeness, I think it should support a request for someBranch~.

I suppose it would be possible then to set up a kind of web service, a listener able to interpret a user query and do the git log master~ on that common server.
That listener wouldn't have anything to do with git.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Shoot.. I was hoping to avoid having to clone an entire repository ust to get a silly little commit hash :( – ajwood Jun 21 '14 at 19:03
  • @ajwood but you don't have to fetch the *all* repo, only the branch you want: http://stackoverflow.com/a/6369199/6309 – VonC Jun 21 '14 at 19:04
  • Even still.. `fetch` is way slower than `ls-remote` – ajwood Jun 21 '14 at 19:09
  • @ajwood I agree. Why do you want to get that remote `master~` SHA1? – VonC Jun 21 '14 at 19:10
  • A custom, perhaps hackish, application. It's a mechanism for users to issue requests to the system for building and installing specific versions of software. It supports `build_request SomeProject someBranch`. For completeness, I think it should support a request for `someBranch~`. – ajwood Jun 21 '14 at 19:21
  • 1
    @ajwood would it be possible then to set up a kind of web service, a listener able to interpret a user query and do the `git log master~` on that common server? That listener wouldn't have anything to do with git. – VonC Jun 21 '14 at 19:29
  • that's a good idea! I've been thinking about a world-writeable clone that anyone could `cd` into for a `fetch/log` and what kind of trouble that could get me into.. – ajwood Jun 21 '14 at 19:42
  • Maybe the intended use would be good to include in the question, and also the separate-service idea in the answer? – jthill Jun 23 '14 at 04:17
  • @jthill I will, I am commuting right now (train). I'll get to it in an hour or so. – VonC Jun 23 '14 at 04:23
0

If your repository is hosted by Github a partial solution consists in using the REST API. It'd be possible to adjust the results by specifying values for sha , per_page and page parameters. The general pattern is

https://api.github.com/repos/USER/REPOSITORY/commits?per_page=NUMBER&sha=SHA_OR_NAME&page=NUMBER

... e.g. SHA of commits in develop..develop~20 range of simelo/skycoin-hardware-wallet repository can be retrieved from the URL https://api.github.com/repos/skycoin/hardware-wallet/commits?per_page=20&sha=develop...

... whereas SHA of commits in develop~15..develop~40 range of simelo/skycoin-hardware-wallet repository can be retrieved from this URL https://api.github.com/repos/skycoin/hardware-wallet/commits?per_page=15&sha=develop&page=2 followed by data extracted from this one https://api.github.com/repos/skycoin/hardware-wallet/commits?per_page=10&sha=develop&page=3

For further instructions about how to get this done from the command line please consult this question.

Olemis Lang
  • 738
  • 7
  • 17