18

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

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

但是当我尝试获取它时,git 告诉我“无法找到 3cc82 ......”

% git fetch ~alice/work/repo stash:new_branch
远程:总计 0(增量 0),重用 0(增量 0)
错误:找不到 3ccc82fb1ee0e7bde1250c7926d333ce21c109c0
致命:找不到对象 3ccc82fb1ee0e7bde1250c7926d333ce21c109c0

有没有办法获取远程存储?

4

3 回答 3

11

是的,你可以,部分。stash只是另一个ref。您可以通过指定具有完整参考路径的参考规范来获取不是头(分支)的参考。

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

但是,如果由于 ref 不存在而没有带有“无效 refspec”的存储,这将失败,因此您最好按需进行。您可以设置一个别名,例如:

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。

于 2015-04-24T05:50:08.770 回答
8

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

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

'tempbranch' 将来自远程的最新存储 (stash@{0})。不幸的是,我不认为 reflog 是从远程分支获取的,因此除非您有权访问源存储库,否则无法获取其他存储区。

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

是否可以将 git stash 推送到远程存储库?

此外,正如我在此期间发现的那样,如果您可以访问源代码库,则 git-send-pack 可以发挥作用:

git send-pack ../myworkingfolder/ stash@{0}:refs/heads/collegue_stash
于 2011-03-10T08:57:26.877 回答
1

您不能,但这为您提供了一条替代路径。 是否有可能将 git-stash 推送到远程存储库

于 2010-02-12T06:50:31.027 回答