[英]How to fetch a remote branch from forked repo to local, and currently forked repo from which branch is pushed is not exist
[英]Can I fetch a stash from a remote repo into a local branch?
一位同事在他們的存儲庫中藏匿了我可以訪問的文件系統(通過文件系統),我想將該存儲庫存入我的存儲庫中的一個分支。
% 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
有沒有辦法可以獲取遠程存儲?
是的,你可以,部分。 藏匿處只是另一個參考 。 您可以通過使用完整的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 send-pack ./ 3ccc82fb1ee0e7bde1250c7926d333ce21c109c0:refs/heads/tempbranch
'tempbranch'將在遙控器的最新藏匿處(藏匿@ {0})。 不幸的是我不認為reflog是從遠程分支獲取的,因此除非你有權訪問源代碼庫,否則無法獲取其他存儲庫。
編寫腳本 :我在上述問題上發布了一個更全面的“腳本化”解決方案
另外,正如我在此期間發現的那樣,如果您有權訪問源代碼庫,git-send-pack可以起作用:
git send-pack ../myworkingfolder/ stash@{0}:refs/heads/collegue_stash
你不能,但這為你提供了另一條路徑。 是-IT-可能對推-A-GIT-藏匿到一個遠程存儲庫
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.