# git-bundle
> 原文: [https://git-scm.com/docs/git-bundle](https://git-scm.com/docs/git-bundle)
## 名稱
git-bundle - 通過歸檔移動對象和引用
## 概要
```
git bundle create <file> <git-rev-list-args>
git bundle verify <file>
git bundle list-heads <file> [<refname>…?]
git bundle unbundle <file> [<refname>…?]
```
## 描述
某些工作流程要求在一臺計算機上的一個或多個開發分支在另一臺計算機上復制,但這兩臺計算機無法直接連接,因此無法使用交互式Git協議(git,ssh,http)。此命令支持 _git fetch_ 和 _git pull_ 通過在原始機器的存檔中打包對象和引用來操作,然后使用 _git fetch將它們導入另一個存儲庫通過某種方式(例如,通過sneakernet)移動存檔后,HTG5]和 _git pull_ 。由于存儲庫之間不存在直接連接,因此用戶必須為目標存儲庫保存的包指定基礎:包假定基礎中的所有對象都已存在于目標存儲庫中。_
## OPTIONS
```
create <file>
```
用于創建名為_文件_的包。這需要 _git-rev-list-args_ 參數來定義包內容。
```
verify <file>
```
用于檢查捆綁包文件是否有效,并將干凈地應用于當前存儲庫。這包括檢查bundle格式本身以及檢查先決條件提交是否存在并在當前存儲庫中完全鏈接。 _git bundle_ 打印缺失提交列表(如果有),并以非零狀態退出。
```
list-heads <file>
```
列出捆綁中定義的引用。如果后跟一個引用列表,則只打印出與給定引用匹配的引用。
```
unbundle <file>
```
將包中的對象傳遞給 _git index-pack_ 以存儲在存儲庫中,然后打印所有已定義引用的名稱。如果給出了引用列表,則僅打印與列表中的引用匹配的引用。這個命令實際上是管道,只能由 _git fetch_ 調用。
```
<git-rev-list-args>
```
_git rev-parse_ 和 _git rev-list_ (包含命名ref,參見下面的SPECIFYING REFERENCES)可接受的參數列表,用于指定特定對象和對傳輸的引用。例如,`master~10..master`導致當前主引用與自其第10個祖先提交以來添加的所有對象一起打包。可以打包的引用和對象的數量沒有明確的限制。
```
[<refname>…?]
```
用于限制報告為可用的引用的引用列表。這主要用于 _git fetch_ ,它希望只接收那些被請求的引用,而不一定是包中的所有東西(在這種情況下, _git bundle_ 就像 _git fetch-pack_ )。
## 指定參考
_git bundle_ 只會打包由 _git show-ref_ 顯示的引用:這包括頭部,標簽和遠程頭部。諸如`master~1`之類的參考文獻無法打包,但非常適合定義基礎。可以打包多個參考,并且可以指定多個參考。包裝的對象是未包含在給定堿基的聯合中的對象。每個基礎可以明確指定(例如`^master~10`),或隱式指定(例如`master~10..master`,`--since=10.days.ago master`)。
目的地使用的基礎非常重要。可以謹慎行事,導致捆綁文件包含目標中已有的對象,因為在目的地解包時會忽略這些對象。
## 例子
假設您要將歷史記錄從計算機A上的存儲庫R1傳輸到計算機B上的另一個存儲庫R2。無論出于何種原因,不允許A和B之間的直接連接,但我們可以通過某種機制將數據從A移動到B. ,電子郵件等)。我們希望通過在R1中的分支主機上進行的開發來更新R2。
要引導該進程,您可以先創建一個沒有任何基礎的包。您可以使用標記記住上次處理的提交,以便以后使用增量包更新其他存儲庫:
```
machineA$ cd R1
machineA$ git bundle create file.bundle master
machineA$ git tag -f lastR2bundle master
```
然后將file.bundle傳輸到目標機器B.由于此捆綁包不需要提取任何現有對象,因此可以通過克隆從機器B上創建新的存儲庫:
```
machineB$ git clone -b master /home/me/tmp/file.bundle R2
```
這將在結果存儲庫中定義一個名為“origin”的遠程,它允許您從包中獲取和提取。 R2中的$ GIT_DIR / config文件將具有如下條目:
```
[remote "origin"]
url = /home/me/tmp/file.bundle
fetch = refs/heads/*:refs/remotes/origin/*
```
要更新生成的mine.git存儲庫,可以在使用增量更新替換存儲在/home/me/tmp/file.bundle中的軟件包之后進行提取或提取。
在原始存儲庫中進行更多工作之后,您可以創建增量包以更新其他存儲庫:
```
machineA$ cd R1
machineA$ git bundle create file.bundle lastR2bundle..master
machineA$ git tag -f lastR2bundle master
```
然后將捆綁包轉移到另一臺機器上以替換/home/me/tmp/file.bundle,并從中拉出。
```
machineB$ cd R2
machineB$ git pull
```
如果您知道預期的收件人存儲庫應該具有必要的對象的提交,您可以使用該知識來指定基礎,給出一個截止點來限制生成的包中的修訂和對象。前面的示例使用lastR2bundle標記用于此目的,但您可以使用您將為 [git-log [1]](https://git-scm.com/docs/git-log) 命令提供的任何其他選項。以下是更多示例:
您可以使用兩者中都存在的標記:
```
$ git bundle create mybundle v1.0.0..master
```
您可以根據時間使用基礎:
```
$ git bundle create mybundle --since=10.days master
```
您可以使用提交次數:
```
$ git bundle create mybundle -10 master
```
您可以運行`git-bundle verify`以查看是否可以從使用基礎創建的包中提取:
```
$ git bundle verify mybundle
```
這將列出您必須具有的提交以從包中提取,如果您沒有它們將會出錯。
從收件人存儲庫的角度來看,捆綁包就像它從中取出或取出的常規存儲庫。例如,您可以在獲取時映射引用:
```
$ git fetch mybundle master:localRef
```
您還可以查看它提供的參考資料:
```
$ git ls-remote mybundle
```
## GIT
部分 [git [1]](https://git-scm.com/docs/git) 套件
- git
- git-config
- git-help
- git-init
- git-clone
- git-add
- git-status
- git-diff
- git-commit
- git-reset
- git-rm
- git-mv
- git-branch
- git-checkout
- git-merge
- git-mergetool
- git-log
- git-stash
- git-tag
- git-worktree
- git-fetch
- git-pull
- git-push
- git-remote
- git-submodule
- git-show
- git-log
- git-shortlog
- git-describe
- git-apply
- git-cherry-pick
- git-rebase
- git-revert
- git-bisect
- git-blame
- git-grep
- gitattributes
- giteveryday
- gitglossary
- githooks
- gitignore
- gitmodules
- gitrevisions
- gittutorial
- gitworkflows
- git-am
- git-format-patch
- git-send-email
- git-request-pull
- git-svn
- git-fast-import
- git-clean
- git-gc
- git-fsck
- git-reflog
- git-filter-branch
- git-instaweb
- git-archive
- git-bundle
- git-daemon
- git-update-server-info
- git-cat-file
- git-check-ignore
- git-checkout-index
- git-commit-tree
- git-count-objects
- git-diff-index
- git-for-each-ref
- git-hash-object
- git-ls-files
- git-merge-base
- git-read-tree
- git-rev-list
- git-rev-parse
- git-show-ref
- git-symbolic-ref
- git-update-index
- git-update-ref
- git-verify-pack
- git-write-tree