代码之家  ›  专栏  ›  技术社区  ›  Matt Curtis

我能从远程回购中取出一个藏匿物到本地分行吗?

  •  18
  • Matt Curtis  · 技术社区  · 16 年前

    一个同事在他们的存储库中有一个存储库,我可以(通过文件系统)访问它,我想将这个存储库拉到我的存储库中的一个分支中。

    % git ls-remote ~alice/work/repo/ stash
    3ccc82fb1ee0e7bde1250c7926d333ce21c109c0        refs/stash
    

    但当我试着去拿的时候,Git告诉我“找不到3cc82…”

    % git fetch ~alice/work/repo stash:new_branch
    remote: Total 0 (delta 0), reused 0 (delta 0)
    error: unable to find 3ccc82fb1ee0e7bde1250c7926d333ce21c109c0
    fatal: object 3ccc82fb1ee0e7bde1250c7926d333ce21c109c0 not found
    

    我有办法取遥控器吗?

    3 回复  |  直到 11 年前
        1
  •  8
  •   Community Mohan Dere    9 年前

    更新 :原始海报问题的直接答案是:

    git send-pack ./ 3ccc82fb1ee0e7bde1250c7926d333ce21c109c0:refs/heads/tempbranch
    

    “tempbranch”将位于 最新的 远程存储(stash@0)。不幸的是,我不认为reflog是从远程分支中提取的,所以没有办法获取其他存储,除非您可以访问源repo。

    脚本编写 :我在上面提到的问题上发布了一个更全面的“脚本化”解决方案。

    Is it possible to push a git stash to a remote repository?

    此外,正如我在此期间发现的,如果您有权访问源repo,那么git send pack将非常有用:

    git send-pack ../myworkingfolder/ stash@{0}:refs/heads/collegue_stash
    
        2
  •  9
  •   sj26    11 年前

    是的,你可以,部分地。这个 stash 只是另一个 ref . 通过指定 refspec 具有完整的引用路径。

    git fetch some-remote +refs/stash:refs/remotes/some-remote/stash
    git stash apply some-remote/stash
    

    您也可以将此配置为在运行普通获取时获取存储:

    git config --add remote.some-remote.fetch +refs/stash:refs/remotes/some-remote/stash
    git fetch some-remote
    git stash apply some-remote/stash
    

    但是如果没有带有“无效refspec”的stash,这将失败,因为ref不存在,所以您最好按需进行。您可以设置如下别名:

    cat > /usr/local/bin/git-fetch-stash
    git fetch --verbose "$1" +refs/stash:refs/remotes/"$1"/stash 
    ^D
    chmod +x /usr/local/bin/git-fetch-stash
    
    git fetch-stash some-remote
    

    需要注意的是,您不能获取多个藏品。这些作为条目存储在 reflog ,并且您无法获取远程的reflog。

        3
  •  1
  •   Community Mohan Dere    9 年前

    不能,但这为您提供了另一条路径。 is-it-possible-to-push-a-git-stash-to-a-remote-repository