bundle

基礎(chǔ)

參考

用于將本地數(shù)據(jù)打包到一個文件中,然后共享給別人

在網(wǎng)絡(luò)不通暢時,可以將本地的修改打包成一個文件,然后通過 U 盤等共享給別人。

create

整個分支

將指定區(qū)間內(nèi)的提交打包成文件。

格式為:git bundle create <file> <git-rev-list-args>。

file 指生成的文件名。

git-rev-list-args 用于指定打包的引用或提交的區(qū)間。

$ 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 分支所需要的所有數(shù)據(jù)。

指定區(qū)間

生成文件時,指定文件包含的結(jié)點的區(qū)間。

如:

$ git bundle create xx.bundle HEAD HEAD~2..HEAD

該命令會將 HEAD~2 (不含) 與 HEAD(含) 之間的結(jié)點生成文件。


解壓

通過 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)到哪個分支。有兩種試解決:

  1. create 時加個 HEAD 選項:
$ git bundle create xx.bundle HEAD master

這樣解壓后,會在本地倉庫生成一個 master 分支。

  1. 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

上述命令說明當前文件中缺少必要的提交信息。


導(dǎo)出數(shù)據(jù)

通過 fetch 或 pull 可以從文件中導(dǎo)出相應(yīng)的數(shù)據(jù),這跟遠程倉庫一樣。

如:

$ git fetch ../xx.bundle master:other-master
From ../commits.bundle
 * [new branch]      master     -> other-master

它會從 xx.bundle 文件中的 master 分支導(dǎo)出到本地的 other-master 分支中。


list-heads

列出軟件包中定義的引用。

如:

$ git bundle list-heads ../xx.bundle
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容