1

Let's assume I have the SHA1 of a commit that's under code review in Gerrit, but not its reference (refs/changes/...)

The question is: how to fetch it from my local repository?

There is a similar question yet Gerrit-unrelated question here: Retrieve specific commit from a remote Git repository

The answer doesn't seem to work with Gerrit:

git fetch origin 67b4b77655d65004cc908aaf7e65b24bcaa81fd8:refs/remotes/origin/foo
fatal: Couldn't find remote ref 67b4b77655d65004cc908aaf7e65b24bcaa81fd8

I can see the commit though if I use git ls-remote:

git ls-remote | grep 67b4b77655d65004cc908aaf7e65b24bcaa81fd8
From ssh://gerrit/repo
67b4b77655d65004cc908aaf7e65b24bcaa81fd8        refs/changes/...

So it looks like Gerrit somehow doesn't look in refs/changes/ during the explicit fetch.

Of course, as a workaround, I can fetch the commit using its refs/changes/... reference, but I was wondering if there is a more direct way, and more importantly, when Gerrit doesn't find the commit when referred to directly by its SHA1.

Community
  • 1
  • 1
ocroquette
  • 3,049
  • 1
  • 23
  • 26
  • Have you tried checking it out first? `git chekcout SHA1` – laplasz Sep 24 '14 at 17:32
  • Yes, it's not in the local repository. – ocroquette Sep 25 '14 at 11:09
  • in git config the _remote.origin.fetch_ param probably contains `+refs/heads/*:refs/remotes/origin/*` but Gerrit commits stored under `refs/changes/` that is why I think you need to know the specific refs to able to fetch it – laplasz Sep 25 '14 at 13:43
  • I appreciate your effort, but that was already clear to me that I can fetch with the reference. The question is: how to fetch using the ID directly? – ocroquette Sep 26 '14 at 15:03
  • Related discussion: https://groups.google.com/forum/#!topic/repo-discuss/Kn1n-DTcjl8 – ocroquette Sep 28 '17 at 19:54

1 Answers1

1

Seems like you have (almost) answered your own question.

git ls-remote | grep 67b4b77655d65004cc908aaf7e65b24bcaa81fd8 |  awk '{system("git fetch origin " $2)}' && git checkout 67b4b77655d65004cc908aaf7e65b24bcaa81fd8 
fracz
  • 20,536
  • 18
  • 103
  • 149
  • Thanks, but I am actually more curious why Gerrit doesn't find a valid commit unless a reference is given, and how to change that. I am not looking for a pragmatical solution, more for an explanation. – ocroquette Sep 27 '14 at 22:03