仅使用提交ID从Gerrit存储库中提取提交 [英] Pull a commit from a Gerrit repository using its commit ID only

查看:43
本文介绍了仅使用提交ID从Gerrit存储库中提取提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我具有Gerrit正在进行代码审查的提交的SHA1,但没有引用(refs/changes/...)

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?

这里还有一个类似Gerrit无关的问题:从远程Git存储库中检索特定的提交

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

答案似乎不适用于Gerrit:

The answer doesn't seem to work with Gerrit:

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

虽然我使用git ls-remote还是可以看到提交内容:

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

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

所以看起来Gerrit在显式访存期间以某种方式没有出现在refs/changes/中.

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

当然,作为一种解决方法,我可以使用其refs/changes/...引用来获取提交,但是我想知道是否有更直接的方法,更重要的是,当Gerrit找不到提交时由其SHA1直接引用.

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.

推荐答案

似乎您(几乎)已经回答了自己的问题.

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

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

这篇关于仅使用提交ID从Gerrit存储库中提取提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆