git中使用bundle

用于将本地数据打包到一个文件中,然后共享给别人

在网络不通畅时,可以将本地的修改打包成一个文件,然后通过 U 盘等共享给别人。

create
整个分支
将指定区间内的提交打包成文件。

格式为:git bundle create 。

file 指生成的文件名。

git-rev-list-args 用于指定打包的引用或提交的区间。

$ git bundle create xx.bundle master
Counting objects: 9, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (9/9), 606 bytes | 606.00 KiB/s, done.
Total 9 (delta 0), reused 0 (delta 0)
该命令会生成 xx.bundle 文件,该文件中饱含生成 master 分支所需要的所有数据。

指定区间
生成文件时,指定文件包含的结点的区间。

如:

$ git bundle create xx.bundle HEAD HEAD~2…HEAD
该命令会将 HEAD~2 (不含) 与 HEAD(含) 之间的结点生成文件。

解压
通过 clone 命令,从 bundle 文件中生成一个 git 库。

与普通 clone 时一样,也可以指定将解压的代码放在哪个文件夹下。

$ git clone xx.bundle xxx
Cloning into ‘bundle’…
Receiving objects: 100% (9/9), done.
warning: remote HEAD refers to nonexistent ref, unable to checkout.
上述命令会从 xx.bundle 文件中生成一个 git 库,同时解压出的文件会存储于 xxx 文件夹下。

但上述解压失败。因为打包时没有指定 HEAD 引用,解压出来后不知道该检出(checkout)到哪个分支。有两种试解决:

create 时加个 HEAD 选项:
$ git bundle create xx.bundle HEAD master
这样解压后,会在本地仓库生成一个 master 分支。

clone 添加 -b 选项
$ git clone -b master xx.bundle dev
注意:此处 -b 生成的分支名,与生成 bundle 文件时的分支名必须一致。

verify
检查生成的包是否合法,也即是说能否成本地解压出来。

如下面的文件是合法的:

$ git bundle verify …/xx.bundle
The bundle contains this ref:
53ac00ed1d79deade77e70d143af251ca1de4d45 HEAD
The bundle requires this ref:
9d8d2c8affa840245cc7bf65b707c09b0b5b167e
…/xx.bundle is okay
而如果文件不合法时,会有如下类似的提示:

$ git bundle verify …/commits-bad.bundle
error: Repository lacks these prerequisite commits:
error: 7011d3d8fc200abe0ad561c011c3852a4b7bbe95 third commit - second repo
上述命令说明当前文件中缺少必要的提交信息。

导出数据
通过 fetch 或 pull 可以从文件中导出相应的数据,这跟远程仓库一样。

如:

$ git fetch …/xx.bundle master:other-master
From …/commits.bundle

  • [new branch] master -> other-master
    它会从 xx.bundle 文件中的 master 分支导出到本地的 other-master 分支中。

list-heads
列出软件包中定义的引用。

如:

$ git bundle list-heads …/xx.bundle

作者:一江碎月
链接:https://www.jianshu.com/p/eebe5dc8ee91
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值