问题描述
备份:
$ git bundle create / tmp / dp --all
$ git bundle list-heads / tmp / dp |头-n5
f37c9fc7f0ce121568f42fb01390b1862c67f308裁判/头/主
f37c9fc7f0ce121568f42fb01390b1862c67f308裁判/头/显示
9aabc2a4fb18181fee6d0e7e03170a976b6ed49b参/遥控器/产地/ NewLayers
aef1fc8a416413ee5b7f4370f255ab654b3407ee参/遥控器/产地/电梯
bc4c78f94a67857fbd7210ecc5ebcd80ec736b1a refs / remotes / origin / elevator_1
$ git bundle verify / tmp / dp |头-n1
/ tmp / dp是好的
该包含65个参考
恢复:
$ git克隆/ tmp / dp dp
克隆到dp ...
$ cd dp
$ git branch -a
* master
remotes / origin / HEAD - >原产地/主产地
遥控器/产地/主产地
遥控器/产地/展示
我尝试了抓取和拉动,但它并没有帮助。
我也尝试用--mirror创建裸回购,然后克隆它,但是结果是一样的。
问题在于克隆远程存储库的远程分支时没有跟踪(以及本地远程回购分支被追踪为远程追踪分支)。你没有在你的问题中说过,但我想用 - mirror
创建的(裸)存储库包含远程跟踪分支。
所以正确的做法是:
$ b $ pre $ git clone --mirror / tmp / dp
mkdir dp
mv dp.git dp / .git
cd dp
git config core.bare false
git reset --hard
(即使用--mirror克隆并撤消隐含的--bare。)
不是很漂亮,但是很有效。或者使用git-init创建一个新的空回购,并将/ tmp / dp定义为远程并行。
fetch = + refs / *:refs / *
而不是普通的
fetch = + refs / heads / *:refs / remotes / remotename / *
并从中获取。
How to restore all remote branches from backup (git bundle).
Backup:
$ git bundle create /tmp/dp --all
$ git bundle list-heads /tmp/dp | head -n5
f37c9fc7f0ce121568f42fb01390b1862c67f308 refs/heads/master
f37c9fc7f0ce121568f42fb01390b1862c67f308 refs/heads/show
9aabc2a4fb18181fee6d0e7e03170a976b6ed49b refs/remotes/origin/NewLayers
aef1fc8a416413ee5b7f4370f255ab654b3407ee refs/remotes/origin/elevator
bc4c78f94a67857fbd7210ecc5ebcd80ec736b1a refs/remotes/origin/elevator_1
$ git bundle verify /tmp/dp | head -n1
/tmp/dp is okay
The bundle contains 65 refs
Restore:
$ git clone /tmp/dp dp
Cloning into dp...
$ cd dp
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/show
I tried fetching and pulling but it didn't help.
I also tried to clone with "--mirror" to create bare repo and then clone from it, but the result was the same.
The problem is that on cloning the remote branches of the remote repository are not tracked (and the local branches of the remote repo are tracked as remote tracking branches). You didn't say in your question but I guess the (bare) repository created with --mirror
included the remote tracking branches.
So the right thing to do is:
git clone --mirror /tmp/dp
mkdir dp
mv dp.git dp/.git
cd dp
git config core.bare false
git reset --hard
(i.e. clone with --mirror and undo the implied --bare.)Not pretty but works. Alternatively create a new empty repo using git-init and define /tmp/dp as remote with a line
fetch = +refs/*:refs/*
instead of the normal
fetch = +refs/heads/*:refs/remotes/remotename/*
and fetch from it.
这篇关于从git包中恢复所有的ref的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!