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

Mat*_*tis 18 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

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

sj2*_*j26 10

是的,你可以,部分.该藏匿处是另一种参考.您可以通过使用完整的ref路径指定refspec来获取不是头(分支)的引用.

git fetch some-remote +refs/stash:refs/remotes/some-remote/stash
git stash apply some-remote/stash
Run Code Online (Sandbox Code Playgroud)

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

git config --add remote.some-remote.fetch +refs/stash:refs/remotes/some-remote/stash
git fetch some-remote
git stash apply some-remote/stash
Run Code Online (Sandbox Code Playgroud)

但是如果没有存储"无效的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
Run Code Online (Sandbox Code Playgroud)

需要注意的是,您无法获取多个藏匿处.它们作为条目存储在reflog中,您无法获取远程的reflog.


seh*_*ehe 8

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

git send-pack ./ 3ccc82fb1ee0e7bde1250c7926d333ce21c109c0:refs/heads/tempbranch
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

git send-pack ../myworkingfolder/ stash@{0}:refs/heads/collegue_stash
Run Code Online (Sandbox Code Playgroud)