Git bundle 添加远程

标签 git

我正在为本地 git 存储库做一个备份脚本。 我查看了各种可能性,然后选择 bundle 来完成任务。 我采取的步骤:

  1. 创建一个新的 repo,进行初始提交

    当我使用 git branch -a 检查 repo 时,我得到以下信息: * 大师

  2. git bundle create ./test.bundle --all

现在,当我使用 git bundle list-heads 检查包时 我得到 2 个引用:1 个用于 HEAD,另一个用于 refs/heads/master。

当我使用 git clone 将这个包 pull 入一个新的存储库时,分支看起来像这样:

*master
remotes/origin/HEAD -> remotes/origin/master
remotes/origin/master

为什么会这样?有没有办法只导入第一个存储库中没有 Remote 的分支?

编辑:

我的问题可能有点不清楚。这是我想要实现的目标:

  1. 有一个包含 2 个分支的 repo,master 和 test。
  2. 捆绑所有分支(按照建议使用 git bundle --branches 完成)
  3. rm 整个 repo
  4. 使用 git clone 恢复 repo。不幸的是,我必须提供一个分支参数,因为没有它我会收到以下错误: 警告:远程 HEAD 引用不存在的 ref,无法 check out 。

出现的唯一问题是我在克隆后得到以下分支:

*master
remotes/origin/master
remotes/origin/test

切换到测试后,我收到一条消息,提示已创建一个新分支。有没有办法克隆所有分支,使其看起来像原始存储库?

*master
test

最佳答案

当您从包中克隆时,包中的分支将看起来像克隆中的 Remote 。这很正常。

尽管 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

也就是说,没有原始 Remote 及其 test1 分支的迹象。

可以创建一个没有远程引用的包,如下所示:

$ git bundle create test.bundle --branches HEAD

但我不确定这是否会产生重大影响。不过,我从未使用过 bundle ,所以也许可以改进这个答案。

更新

当您从 bundle 克隆时,从您的新克隆的角度来看,bundle 被视为一个远程的新源。克隆时,只为 HEAD 创建一个本地分支,其他分支留在原点。如果你想完全摆脱 bundle,你可以为 bundle remote (= origin) 中的所有分支创建本地分支,然后删除 remote 并删除 bundle,像这样:

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

在运行此之前,请确保您处于干净状态,没有未决或暂存的更改。

关于Git bundle 添加远程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20446528/

相关文章:

node.js - 使用 git 部署到 digitalocean 上的 dokku

附加到 Outlook 电子邮件的 Git 补丁文件被它修改

git - 防止打开 ST3 时显示旧代码

windows - 如何在 Windows 上将 man 和 zip 添加到 "git bash"安装

mysql - 如何在持续交付中为 WordPress 执行高级数据库 merge ?

git - 如何从本地分支 `git push` 隐式 "X"到 "origin/Y"

git - 关于 SVN <-> Git 工作流的建议

git - 删除名称与特定模式匹配的 git 分支

php - 如何在我的开发网站的页面顶部显示当前的 git 分支名称?

iOS Git 和 Cocoapods - 如何对通过 Cocoapods 添加的模块进行自定义?