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

不羁的心 提交于 2019-12-11 09:34:16

问题


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.


回答1:


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

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


来源:https://stackoverflow.com/questions/26021613/pull-a-commit-from-a-gerrit-repository-using-its-commit-id-only

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