ocroquette
ocroquette

Reputation: 3259

Pull a commit from a Gerrit repository using its commit ID only

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.

Upvotes: 1

Views: 2769

Answers (1)

fracz
fracz

Reputation: 21249

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

git ls-remote | grep 67b4b77655d65004cc908aaf7e65b24bcaa81fd8 |  awk '{system("git fetch origin " $2)}' && git checkout 67b4b77655d65004cc908aaf7e65b24bcaa81fd8 

Upvotes: 1

Related Questions