Skip to content

Commit 2e0afaf

Browse files
dschoJunio C Hamano
authored andcommitted
Add git-bundle: move objects and references by archive
Some workflows require use of repositories on machines that cannot be connected, preventing use of git-fetch / git-push to transport objects and references between the repositories. git-bundle provides an alternate transport mechanism, effectively allowing git-fetch and git-pull to operate using sneakernet transport. `git-bundle create` allows the user to create a bundle containing one or more branches or tags, but with specified basis assumed to exist on the target repository. At the receiving end, git-bundle acts like git-fetch-pack, allowing the user to invoke git-fetch or git-pull using the bundle file as the URL. git-fetch and git-ls-remote determine they have a bundle URL by checking that the URL points to a file, but are otherwise unchanged in operation with bundles. The original patch was done by Mark Levedahl <[email protected]>. It was updated to make git-bundle a builtin, and get rid of the tar format: now, the first line is supposed to say "# v2 git bundle", the next lines either contain a prerequisite ("-" followed by the hash of the needed commit), or a ref (the hash of a commit, followed by the name of the ref), and finally the pack. As a result, the bundle argument can be "-" now. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 437b1b2 commit 2e0afaf

File tree

11 files changed

+575
-4
lines changed

11 files changed

+575
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ git-archive
1313
git-bisect
1414
git-blame
1515
git-branch
16+
git-bundle
1617
git-cat-file
1718
git-check-ref-format
1819
git-checkout

Documentation/cmd-list.perl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ sub format_one {
7070
git-bisect mainporcelain
7171
git-blame ancillaryinterrogators
7272
git-branch mainporcelain
73+
git-bundle mainporcelain
7374
git-cat-file plumbinginterrogators
7475
git-checkout-index plumbingmanipulators
7576
git-checkout mainporcelain

Documentation/git-bundle.txt

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
git-bundle(1)
2+
=============
3+
4+
NAME
5+
----
6+
git-bundle - Move objects and refs by archive
7+
8+
9+
SYNOPSIS
10+
--------
11+
'git-bundle' create <file> [git-rev-list args]
12+
'git-bundle' verify <file>
13+
'git-bundle' list-heads <file> [refname...]
14+
'git-bundle' unbundle <file> [refname...]
15+
16+
DESCRIPTION
17+
-----------
18+
19+
Some workflows require that one or more branches of development on one
20+
machine be replicated on another machine, but the two machines cannot
21+
be directly connected so the interactive git protocols (git, ssh,
22+
rsync, http) cannot be used. This command provides suport for
23+
git-fetch and git-pull to operate by packaging objects and references
24+
in an archive at the originating machine, then importing those into
25+
another repository using gitlink:git-fetch[1] and gitlink:git-pull[1]
26+
after moving the archive by some means (i.e., by sneakernet). As no
27+
direct connection between repositories exists, the user must specify a
28+
basis for the bundle that is held by the destination repository: the
29+
bundle assumes that all objects in the basis are already in the
30+
destination repository.
31+
32+
OPTIONS
33+
-------
34+
35+
create <file>::
36+
Used to create a bundle named 'file'. This requires the
37+
git-rev-list arguments to define the bundle contents.
38+
39+
verify <file>::
40+
Used to check that a bundle file is valid and will apply
41+
cleanly to the current repository. This includes checks on the
42+
bundle format itself as well as checking that the prerequisite
43+
commits exist and are fully linked in the current repository.
44+
git-bundle prints a list of missing commits, if any, and exits
45+
with non-zero status.
46+
47+
list-heads <file>::
48+
Lists the references defined in the bundle. If followed by a
49+
list of references, only references matching those given are
50+
printed out.
51+
52+
unbundle <file>::
53+
Passes the objects in the bundle to gitlink:git-index-pack[1]
54+
for storage in the repository, then prints the names of all
55+
defined references. If a reflist is given, only references
56+
matching those in the given list are printed. This command is
57+
really plumbing, intended to be called only by
58+
gitlink:git-fetch[1].
59+
60+
[git-rev-list-args...]::
61+
A list of arguments, accepatble to git-rev-parse and
62+
git-rev-list, that specify the specific objects and references
63+
to transport. For example, "master~10..master" causes the
64+
current master reference to be packaged along with all objects
65+
added since its 10th ancestor commit. There is no explicit
66+
limit to the number of references and objects that may be
67+
packaged.
68+
69+
70+
[refname...]::
71+
A list of references used to limit the references reported as
72+
available. This is principally of use to git-fetch, which
73+
expects to recieve only those references asked for and not
74+
necessarily everything in the pack (in this case, git-bundle is
75+
acting like gitlink:git-fetch-pack[1]).
76+
77+
SPECIFYING REFERENCES
78+
---------------------
79+
80+
git-bundle will only package references that are shown by
81+
git-show-ref: this includes heads, tags, and remote heads. References
82+
such as master~1 cannot be packaged, but are perfectly suitable for
83+
defining the basis. More than one reference may be packaged, and more
84+
than one basis can be specified. The objects packaged are those not
85+
contained in the union of the given bases. Each basis can be
86+
specified explicitly (e.g., ^master~10), or implicitly (e.g.,
87+
master~10..master, master --since=10.days.ago).
88+
89+
It is very important that the basis used be held by the destination.
90+
It is ok to err on the side of conservatism, causing the bundle file
91+
to contain objects already in the destination as these are ignored
92+
when unpacking at the destination.
93+
94+
EXAMPLE
95+
-------
96+
97+
Assume two repositories exist as R1 on machine A, and R2 on machine B.
98+
For whatever reason, direct connection between A and B is not allowed,
99+
but we can move data from A to B via some mechanism (CD, email, etc).
100+
We want to update R2 with developments made on branch master in R1.
101+
We set a tag in R1 (lastR2bundle) after the previous such transport,
102+
and move it afterwards to help build the bundle.
103+
104+
in R1 on A:
105+
$ git-bundle create mybundle master ^lastR2bundle
106+
$ git tag -f lastR2bundle master
107+
108+
(move mybundle from A to B by some mechanism)
109+
110+
in R2 on B:
111+
$ git-bundle verify mybundle
112+
$ git-fetch mybundle refspec
113+
114+
where refspec is refInBundle:localRef
115+
116+
117+
Also, with something like this in your config:
118+
119+
[remote "bundle"]
120+
url = /home/me/tmp/file.bdl
121+
fetch = refs/heads/*:refs/remotes/origin/*
122+
123+
You can first sneakernet the bundle file to ~/tmp/file.bdl and
124+
then these commands:
125+
126+
$ git ls-remote bundle
127+
$ git fetch bundle
128+
$ git pull bundle
129+
130+
would treat it as if it is talking with a remote side over the
131+
network.
132+
133+
Author
134+
------
135+
Written by Mark Levedahl <[email protected]>
136+
137+
GIT
138+
---
139+
Part of the gitlink:git[7] suite

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ BUILTIN_OBJS = \
271271
builtin-archive.o \
272272
builtin-blame.o \
273273
builtin-branch.o \
274+
builtin-bundle.o \
274275
builtin-cat-file.o \
275276
builtin-checkout-index.o \
276277
builtin-check-ref-format.o \

0 commit comments

Comments
 (0)