【问题标题】:Referencing the sha1 in one local repo from within another local repo in git从 git 中的另一个本地存储库中引用一个本地存储库中的 sha1
【发布时间】:2011-08-19 21:03:20
【问题描述】:

我在本地机器上克隆了两个 git 存储库。我正在尝试将更改从一个回购应用到另一个:

cd path/to/local-repo1
git fetch path/to/local-repo2 <sha1>
// cherry-pick from fetch head, etc.

我明白了:

fatal: Couldn't find remote ref <sha1>
fatal: The remote end hung up unexpectedly

我找到了git: Apply changes introduced by commit in one repo to another repo,但为什么 git 无法识别另一个本地 repo 中的 sha1?事实证明,如果我用分支名称替换 sha1,它会成功,但我需要使用大量 sha1 来执行此操作,并且真的不想在每个分支上创建一个分支以引用它们。

【问题讨论】:

  • 这不是您特定问题的答案,但您没有创建分支并获取每个分支。您可以添加local-repo2 作为远程和git fetch local-repo2,然后挑选哈希值。

标签: git repository fetch sha1


【解决方案1】:

您尝试使用的git fetch 的形式是:

git fetch <repository> <refspec>

但是,您的 SHA1sum 是(不太可能是!)有效的参考规范。 refspec 定义了源和目标存储库之间的 refs(通常是分支名称)之间的映射。 SHA1sums(对象名称)与 refs 不同,错误告诉您,当您执行 git fetch path/to/local-repo2 f414f31 时,它会将 refspec 扩展为 f414f31:f414f31,然后无法在远程存储库中找到 ref f414f31。那是因为它不是参考。

因此,假设您的提交位于远程存储库的本地分支上,我将执行以下操作:

git remote add other-local path/to/local-repo2
git fetch other-local
git cherry-pick f414f31

git fetch &lt;remote-name&gt; 形式将远程存储库中的所有本地分支获取到refs/remotes/&lt;remote-name&gt; 下的远程跟踪分支,并确保这些分支所需的所有对象(包括历史记录中的所有提交)都存在于您的本地存储库。

【讨论】:

    猜你喜欢
    • 2014-09-06
    • 2011-07-23
    • 2018-04-30
    • 2014-10-20
    • 2016-07-14
    • 2017-09-09
    • 2016-04-06
    • 2021-09-18
    相关资源
    最近更新 更多