You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/07-git-tools/sections/bundling.asc
+64Lines changed: 64 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,28 @@
1
1
[[_bundling]]
2
+
//////////////////////////
3
+
=== Bundling
4
+
//////////////////////////
2
5
=== Bundling
3
6
7
+
//////////////////////////
4
8
Though we've covered the common ways to transfer Git data over a network (HTTP, SSH, etc), there is actually one more way to do so that is not commonly used but can actually be quite useful.
Git is capable of ``bundling'' it's data into a single file. This can be useful in various scenarios. Maybe your network is down and you want to send changes to your co-workers. Perhaps you're working somewhere offsite and don't have access to the local network for security reasons. Maybe your wireless/ethernet card just broke. Maybe you don't have access to a shared server for the moment, you want to email someone updates and you don't want to transfer 40 commits via `format-patch`.
This is where the `git bundle` command can be helpful. The `bundle` command will package up everything that would normally be pushed over the wire with a `git push` command into a binary file that you can email to someone or put on a flash drive, then unbundle into another repository.
19
+
//////////////////////////
20
+
そんなとき、`git bundle` コマンドが役に立つでしょう。このコマンドを使うと、`git push` コマンドで転送されるのと同内容のデータを単一のバイナリファイルにまとめてくれます。あとは、そのファイルをメールで送るか USB メモリに入れるなどしておいて、別のリポジトリ上で展開すればいいのです。
9
21
22
+
//////////////////////////
10
23
Let's see a simple example. Let's say you have a repository with two commits:
If you want to send that repository to someone and you don't have access to a repository to push to, or simply don't want to set one up, you can bundle it with `git bundle create`.
Now you have a file named `repo.bundle` that has all the data needed to re-create the repository's `master` branch. With the `bundle` command you need to list out every reference or specific range of commits that you want to be included. If you intend for this to be cloned somewhere else, you should add HEAD as a reference as well as we've done here.
On the other side, say you are sent this `repo.bundle` file and want to work on the project. You can clone from the binary file into a directory, much like you would from a URL.
If you don't include HEAD in the references, you have to also specify `-b master` or whatever branch is included because otherwise it won't know what branch to check out.
85
+
//////////////////////////
86
+
まとめる対象として HEAD が含まれていないと、ここで、 `-b master` のように、なんらかのブランチを指定しなければなりません。そうしないと、どのブランチをチェックアウトすべきか、判断する術がないからです。
57
87
88
+
//////////////////////////
58
89
Now let's say you do three commits on it and want to send the new commits back via a bundle on a USB stick or email.
@@ -67,9 +101,15 @@ c99cf5b fourth commit - second repo
67
101
b1ec324 first commit
68
102
----
69
103
104
+
//////////////////////////
70
105
First we need to determine the range of commits we want to include in the bundle. Unlike the network protocols which figure out the minimum set of data to transfer over the network for us, we'll have to figure this out manually. Now, you could just do the same thing and bundle the entire repository, which will work, but it's better to just bundle up the difference - just the three commits we just made locally.
In order to do that, you'll have to calculate the difference. As we described in <<_commit_ranges>>, you can specify a range of commits in a number of ways. To get the three commits that we have in our master branch that weren't in the branch we originally cloned, we can use something like `origin/master..master` or `master ^origin/master`. You can test that with the `log` command.
@@ -79,7 +119,10 @@ c99cf5b fourth commit - second repo
79
119
7011d3d third commit - second repo
80
120
----
81
121
122
+
//////////////////////////
82
123
So now that we have the list of commits we want to include in the bundle, let's bundle them up. We do that with the `git bundle create` command, giving it a filename we want our bundle to be and the range of commits we want to go into it.
Now we have a `commits.bundle` file in our directory. If we take that and send it to our partner, she can then import it into the original repository, even if more work has been done there in the meantime.
When she gets the bundle, she can inspect it to see what it contains before she imports it into her repository. The first command is the `bundle verify` command that will make sure the file is actually a valid Git bundle and that you have all the necessary ancestors to reconstitute it properly.
@@ -105,7 +154,10 @@ The bundle requires these 1 ref
105
154
../commits.bundle is okay
106
155
----
107
156
157
+
//////////////////////////
108
158
If the bundler had created a bundle of just the last two commits they had done, rather than all three, the original repository would not be able to import it, since it is missing requisite history. The `verify` command would have looked like this instead:
@@ -114,15 +166,21 @@ error: Repository lacks these prerequisite commits:
114
166
error: 7011d3d8fc200abe0ad561c011c3852a4b7bbe95 third commit - second repo
115
167
----
116
168
169
+
//////////////////////////
117
170
However, our first bundle is valid, so we can fetch in commits from it. If you want to see what branches are in the bundle that can be imported, there is also a command to just list the heads:
The `verify` sub-command will tell you the heads as well. The point is to see what can be pulled in, so you can use the `fetch` or `pull` commands to import commits from this bundle. Here we'll fetch the 'master' branch of the bundle to a branch named 'other-master' in our repository:
Now we can see that we have the imported commits on the 'other-master' branch as well as any commits we've done in the meantime in our own 'master' branch.
So, `git bundle` can be really useful for sharing or doing network-type operations when you don't have the proper network or shared repository to do so.
0 commit comments