我正在为本地git repo做一个备份脚本。我仔细研究了可能性,然后选择捆绑包来完成任务。我已采取的步骤:
创建一个新的仓库,进行初始提交
当我检查仓库时,git branch -a
我得到以下信息:* master
git bundle create ./test.bundle --all
到现在,当我检查捆绑包时,git bundle list-heads
我得到2个参考:1个是HEAD,另一个是refs / heads / master。
当我使用将包捆绑到新的存储库中时git clone
,分支看起来像这样:
*master
remotes/origin/HEAD -> remotes/origin/master
remotes/origin/master
为什么会这样?有没有一种方法可以只导入第一个存储库中没有远程位置的分支?
编辑:
我的问题可能还不清楚。这是我想要实现的目标:
git bundle --branches
按照建议完成)rm
整个回购warning: remote HEAD refers to nonexistent ref, unable to checkout.
出现的唯一问题是克隆后我得到了以下分支:
*master
remotes/origin/master
remotes/origin/test
切换到测试后,我收到一条消息,提示已建立一个新分支。有没有一种方法可以克隆所有分支,使其看起来像原始回购协议?
*master
test
从捆绑中克隆时,捆绑中的分支看起来像克隆中的远程节点。那很正常
尽管git bundle list-heads
显示了原始存储库的远程引用,但您不会在新克隆中看到它们。我的意思是例如:
$ git bundle list-heads test.bundle
a742ee94e8fcef80eb5619f76674bb79d7011742 refs/heads/test2
a8bf0cf603a686ccb75179c64b3392d50ff2f4af refs/heads/master
a8bf0cf603a686ccb75179c64b3392d50ff2f4af refs/remotes/origin/HEAD
a8bf0cf603a686ccb75179c64b3392d50ff2f4af refs/remotes/origin/master
a8bf0cf603a686ccb75179c64b3392d50ff2f4af refs/remotes/origin/test1
a8bf0cf603a686ccb75179c64b3392d50ff2f4af HEAD
然后从中克隆:
$ git clone test.bundle clone2
$ cd clone2
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/test2
也就是说,没有任何迹象表明原始遥控器带有其test1
分支。
您可以创建一个没有远程引用的bundle,如下所示:
$ git bundle create test.bundle --branches HEAD
但是我不确定这是否会有很大的不同。不过,我从未使用过捆绑软件,因此也许可以改善此答案。
更新
从捆绑软件克隆时,从新克隆的角度来看,捆绑软件被视为远程的新来源。克隆时,仅为HEAD创建一个本地分支,其他分支留在原点。如果要完全摆脱捆绑软件,则可以为捆绑软件远程服务器(= origin)中的所有分支创建本地分支,然后放下遥控器并删除捆绑软件,如下所示:
for b in $(git branch -r | grep -v HEAD | cut -f2 -d/); do
git show-ref --verify --quiet refs/heads/$b || git checkout $b
done
在运行此程序之前,请确保您处于干净状态,没有挂起的或分阶段的更改。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句