简体   繁体   English

仅使用提交ID从Gerrit存储库中提取提交

[英]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/...) 假设我具有Gerrit代码审查中的提交的SHA1,但没有引用(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 这里有一个类似的问题,但与Gerrit无关: 从远程Git存储库中检索特定的提交

The answer doesn't seem to work with Gerrit: 答案似乎不适用于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,我可以看到提交:

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. 所以看起来Gerrit在显式访存期间不知何故不在refs / changes /中。

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

好像您(几乎)回答了自己的问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM