gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 01:25:51 26 4
gpt4 key购买 nike

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

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

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

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

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

最佳答案

是的,你可以,部分地。 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”的存储,这将失败,因为 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。

关于git - 我可以从远程存储库中获取存储到本地分支吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2248680/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com