我可以从远程仓库获取存储到本地分支吗?

时间:2010-02-11 23:53:33

标签: git git-stash

一位同事在他们的存储库中藏匿了我可以访问的文件系统(通过文件系统),我想把这个藏匿点存入我的存储库中的一个分支。

% 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 个答案:

答案 0 :(得分:10)

是的,你可以,部分。 stash只是另一个ref。您可以通过使用完整的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”,因为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。

答案 1 :(得分:8)

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

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

'tempbranch'将来自遥控器的最新藏匿处(藏匿@ {0})。不幸的是,我不认为reflog是从远程分支获取的,所以除非你有权访问源代码库,否则无法获取其他存储库。

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

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

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

git send-pack ../myworkingfolder/ stash@{0}:refs/heads/collegue_stash

答案 2 :(得分:1)

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

相关问题