์์์ Git ๋ฐ์ดํฐ๋ฅผ ๋คํธ์ํฌ๋ฅผ ๊ฑฐ์ณ ์ ์กํ๋ ์ผ๋ฐ์ ์ธ ๋ฐฉ๋ฒ(HTTP, SSH๋ฑ)์ ๋ค๋ฃจ์์๋ค. ์ผ๋ฐ์ ์ผ๋ก ์ฌ์ฉํ์ง ์์ง๋ง, ๊ฝค ์ ์ฉํ ๋ฐฉ๋ฒ์ด ํ๋ ๋ ์๋ค.
Git์๋ โBundleโ ์ด๋ ๊ฒ์ด ์๋ค. ๋ฐ์ดํฐ๋ฅผ ํ ํ์ผ์ ๋ชฐ์๋ฃ๋ ๊ฒ์ด๋ค.
์ด ๋ฐฉ๋ฒ์ ๋ค์ํ ๊ฒฝ์ฐ ์ ์ฉํ๊ฒ ์ฌ์ฉํ ์ ์๋ค.
์๋ฅผ ๋ค์ด ๋คํธ์ํฌ๊ฐ ๋ถํต์ธ๋ฐ ๋ณ๊ฒฝ์ฌํญ์ ๋๋ฃ์๊ฒ ๋ณด๋ผ ๋,
์ถ์ฅ์ ๋๊ฐ๋๋ฐ ๋ณด์์์ ์ด์ ๋ก ๋ก์ปฌ ๋คํธ์ํฌ์ ์ ์ํ์ง ๋ชปํ ๋,
ํต์ ์ธํฐํ์ด์ค ์ฅ๋น๊ฐ ๊ณ ์ฅ๋ฌ์ ๋,
๊ฐ์๊ธฐ ๊ณต์ฉ ์๋ฒ์ ์ ๊ทผํ์ง ๋ชปํ ๋, ๋๊ตฐ๊ฐ์๊ฒ ์์ ์ฌํญ์ ์ด๋ฉ์ผ๋ก ๋ณด๋ด์ผ ํ๋๋ฐ 40๊ฐ ์ฉ์ด๋ ๋๋ ์ปค๋ฐ์ format-patch ๋ก ๋ณด๋ด๊ณ ์ถ์ง ์์ ๋๋ฅผ ์๋ก ๋ค ์ ์๋ค.
๋ฐ๋ก ์ด๋ด ๋ git bundle ์ด ํ ์ค๊ธฐ ๋น์ด ๋์ด์ค๋ค.
bundle ๋ช
๋ น์ ๋ณดํต git push ๋ช
๋ น์ผ๋ก ์ฌ๋ ค ๋ณด๋ผ ๋ชจ๋ ๊ฒ์ ๊ฐ์ธ์ ํ ๋ฐ์ด๋๋ฆฌ ํ์ผ๋ก ๋ง๋ ๋ค. ์ด ํ์ผ์ ์ด๋ฉ์ผ๋ก ๋ณด๋ด๊ฑฐ๋ USB๋ก ๋ค๋ฅธ ์ฌ๋์๊ฒ ๋ณด๋ด์ ๋ค๋ฅธ ์ ์ฅ์์ ํ์ด์(Unbundle) ์ฌ์ฉํ๋ค.
๊ฐ๋จํ ์์ ๋ฅผ ๋ณด์. ์ด ์ ์ฅ์์๋ ์ปค๋ฐ ๋ ๊ฐ๊ฐ ์๋ค.
$ git log
commit 9a466c572fe88b195efd356c3f2bbeccdb504102
Author: Scott Chacon <schacon@gmail.com>
Date: Wed Mar 10 07:34:10 2010 -0800
second commit
commit b1ec3248f39900d2a406049d762aa68e9641be25
Author: Scott Chacon <schacon@gmail.com>
Date: Wed Mar 10 07:34:01 2010 -0800
first commit์ด ์ ์ฅ์๋ฅผ ๋ค๋ฅธ ์ฌ๋์๊ฒ ํต์งธ๋ก ๋ณด๋ด๊ณ ์ถ์๋ฐ ๊ทธ ์ฌ๋์ ์ ์ฅ์์ Push ํ ๊ถํ์ด ์๊ฑฐ๋, ๊ทธ๋ฅ Push ํ๊ณ ์ถ์ง ์์ ๋, git bundle create ๋ช
๋ น์ผ๋ก Bundle์ ๋ง๋ค ์ ์๋ค.
$ git bundle create repo.bundle HEAD master
Counting objects: 6, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (6/6), 441 bytes, done.
Total 6 (delta 0), reused 0 (delta 0)์ด๋ ๊ฒ repo.bundle ์ด๋ผ๋ ์ด๋ฆ์ ํ์ผ์ ์์ฑํ ์ ์๋ค. ์ด ํ์ผ์๋ ์ด ์ ์ฅ์์ master ๋ธ๋์น๋ฅผ ๋ค์ ๋ง๋๋ ๋ฐ ํ์ํ ๋ชจ๋ ์ ๋ณด๊ฐ ๋ค ๋ค์ด ์๋ค.
bundle ๋ช
๋ น์ผ๋ก ๋ชจ๋ Refs๋ฅผ ํฌํจํ๊ฑฐ๋ Bundle์ ํฌํจํ ํน์ ๊ตฌ๊ฐ์ ์ปค๋ฐ์ ์ง์ ํ ์ ์๋ค.
์ด Bundle์ ๋ค๋ฅธ ๊ณณ์์ Clone ํ๋ ค๋ฉด ์์ ๋ช
๋ น์ฒ๋ผ HEAD Refs๋ฅผ ํฌํจํด์ผ ํ๋ค.
repo.bundle ํ์ผ์ ๋ค๋ฅธ ์ฌ๋์๊ฒ ์ด๋ฉ์ผ๋ก ์ ์กํ๊ฑฐ๋ USB ๋๋ผ์ด๋ธ์ ๋ด์์ ๋๊ฐ ์ ์๋ค.
ํน์ repo.bundle ํ์ผ์ ์ผํ ๊ณณ์ผ๋ก ์ด๋ป๊ฒ๋ ๋ณด๋ด๋์ผ๋ฉด
์ด Bundle ํ์ผ์ ๋ง์น URL์์ ๊ฐ์ ธ์จ ๊ฒ์ฒ๋ผ Clone ํด์ ์ฌ์ฉํ ์ ์๋ค.
$ git clone repo.bundle repo
Cloning into 'repo'...
...
$ cd repo
$ git log --oneline
9a466c5 second commit
b1ec324 first commitBundle ํ์ผ์ HEAD Refs๋ฅผ ํฌํจํ์ง ์์ผ๋ ค๋ฉด -b master ์ต์
์ ์จ์ฃผ๊ฑฐ๋ ํฌํจ์ํฌ ๋ธ๋์น๋ฅผ ์ง์ ํด์ค์ผ ํ๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด Git์ ์ด๋ค ๋ธ๋์น๋ก Checkout ํ ์ง ์ ์ ์๋ค.
์ด์ ์ ์ปค๋ฐ ์ธ ๊ฐ๋ฅผ ์ถ๊ฐํด์ ์ฑ์ด ์ ์ฅ์๋ฅผ ๋ค์ ์๋ Bundle์ ๋ง๋ค์๋ ์ ์ฅ์๋ก USB๋ ๋ฉ์ผ์ด๋ Bundle๋ก ๋ณด๋ด ์ ์ปค๋ฐ์ ์ฎ๊ฒจ๋ณด์.
$ git log --oneline
71b84da last commit - second repo
c99cf5b fourth commit - second repo
7011d3d third commit - second repo
9a466c5 second commit
b1ec324 first commit๋จผ์ Bundle ํ์ผ์ ์ถ๊ฐ์ํฌ ์ปค๋ฐ์ ๋ฒ์๋ฅผ ์ ํด์ผ ํ๋ค. ์ ์กํ ์ต์ํ์ ๋ฐ์ดํฐ๋ฅผ ์์์ ์ธ์ํ๋ ๋คํธ์ํฌ ํ๋กํ ์ฝ๊ณผ๋ ๋ฌ๋ฆฌ Bundle ๋ช ๋ น์ ์ฌ์ฉํ ๋๋ ์๋์ผ๋ก ์ง์ ํด์ผ ํ๋ค. ์ ์ฒด ์ ์ฅ์๋ฅผ Bundle ํ์ผ๋ก ๋ง๋ค ์๋ ์์ง๋ง, ์ฐจ์ด์ ๋ง Bundle๋ก ๋ฌถ๋ ๊ฒ ์ข๋ค. ์์ ์์๋ ๋ก์ปฌ์์ ๋ง๋ ์ธ ๊ฐ์ ์ปค๋ฐ๋ง ๋ฌถ๋๋ค.
์ฐ์ ์ฐจ์ด์ ์ ์ฐพ์๋ด์ผ Bundle ํ์ผ์ ๋ง๋ค ์ ์๋ค.
ch07-git-tools.asc์์ ์ดํด๋ณธ ๋๋ก ์ซ์๋ฅผ ์ฌ์ฉํ์ฌ ์ปค๋ฐ์ ๋ฒ์๋ฅผ ์ง์ ํ ์ ์๋ค.
์๋ Clone ํ ๋ธ๋์น์ธ master์๋ ์๋ ์ธ ๊ฐ์ ์ปค๋ฐ์ ์ป์ด๋ด๋ ค๋ฉด origin/master..master ๋๋ master ^origin/master ํ๋ผ๋ฏธํฐ๋ฅผ ์ฐ๋ฉด ๋๋ค.
log ๋ช
๋ น์ผ๋ก ์ํํด๋ณผ ์ ์๋ค.
$ git log --oneline master ^origin/master
71b84da last commit - second repo
c99cf5b fourth commit - second repo
7011d3d third commit - second repo์ด์ Bundle ํ์ผ์ ํฌํจํ ์ปค๋ฐ์ ์ป์์ผ๋ ๋ฌถ์ด๋ณด์.
git bundle create ๋ช
๋ น์ Bundle ํ์ผ์ ์ด๋ฆ๊ณผ ๋ฌถ์ด ๋ฃ์ ์ปค๋ฐ์ ๋ฒ์๋ฅผ ์ง์ ํ๋ค.
$ git bundle create commits.bundle master ^9a466c5
Counting objects: 11, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (9/9), 775 bytes, done.
Total 9 (delta 0), reused 0 (delta 0)์ด์ ๋๋ ํ ๋ฆฌ์ commits.bundle ํ์ผ์ด ์๊ฒผ๋ค.
์ด ํ์ผ์ ๋๋ฃ์๊ฒ ๋ณด๋ด๋ฉด ์๋์ ์ ์ฅ์์ ์ผ์ด ์ผ๋ง๋ ์งํ๋์๋ ๊ฐ์ ํ์ผ ๋ด์ฉ์ ์ ์ฉํ ์ ์๋ค.
์ด Bundle ํ์ผ์ ๋๋ฃ๊ฐ ๋ฐ์์ผ๋ฉด ์๋ ์ ์ฅ์์ ์ ์ฉํ๊ธฐ ์ ์ ๋ฌด์์ด ๋ค์ด ์๋์ง ์ดํด๋ณผ ์ ์๋ค.
์ฐ์ bundle verify ๋ช
๋ น์ผ๋ก ํ์ผ์ด ์ฌ๋ฐ๋ฅธ Git Bundle์ธ๊ฐ, ์ ๋๋ก ์ ์ฉํ๋ ๋ฐ ํ์ํ ๋ชจ๋ ํ์คํ ๋ฆฌ๊ฐ ํ์ฌ ์ ์ฅ์์ ์๋๊ฐ ํ์ธํ๋ค.
$ git bundle verify ../commits.bundle
The bundle contains 1 ref
71b84daaf49abed142a373b6e5c59a22dc6560dc refs/heads/master
The bundle requires these 1 ref
9a466c572fe88b195efd356c3f2bbeccdb504102 second commit
../commits.bundle is okay๋ง์ฝ ์์์ Bundle ํ์ผ์ ๋ง๋ค ๋ ์ปค๋ฐ ์ธ ๊ฐ๋ก ๋ง๋ค์ง ์๊ณ ๋ง์ง๋ง ๋ ์ปค๋ฐ์ผ๋ก๋ง Bundle ํ์ผ์ ๋ง๋ค๋ฉด ์ปค๋ฐ์ด ๋ชจ์๋ผ๊ธฐ ๋๋ฌธ์ ์ต์ด์ Bundle์ ๋ง๋ค์๋ ์ ์ฅ์์ ์ Bundle ํ์ผ์ ํฉ์น ์ ์๋ค.
์ด๋ฐ ๋ฌธ์ ๋ฅผ verify ๋ช
๋ น์ผ๋ก ํ์ธํ ์ ์๋ค.
$ git bundle verify ../commits-bad.bundle
error: Repository lacks these prerequisite commits:
error: 7011d3d8fc200abe0ad561c011c3852a4b7bbe95 third commit - second repo์ ๋๋ก ๋ง๋ Bundle ํ์ผ์ด๋ผ๋ฉด ์ปค๋ฐ์ ๊ฐ์ ธ์์ ์ต์ด ์ ์ฅ์์ ํฉ์น ์ ์๋ค. ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ฌ Bundle ํ์ผ์ ์ด๋ค ๋ธ๋์น๋ฅผ ํฌํจํ๊ณ ์๋์ง ์ดํด๋ณด๋ ค๋ฉด ์๋์ ๊ฐ์ ๋ช ๋ น์ผ๋ก ํ์ธํ ์ ์๋ค.
$ git bundle list-heads ../commits.bundle
71b84daaf49abed142a373b6e5c59a22dc6560dc refs/heads/master์์์ verify ๋ช
๋ น์ ์คํํ์ ๋๋ ๋ธ๋์น ์ ๋ณด๋ฅผ ํ์ธํ ์ ์๋ค.
์ฌ๊ธฐ์ ์ค์ํ๊ฒ ์ง์ ๋ถ๋ถ์ fetch ๋ช
๋ น์ด๋ pull ๋ช
๋ น์ผ๋ก ๊ฐ์ ธ์ฌ ๋์์ด ๋๋ ๋ธ๋์น๋ฅผ Bundle ํ์ผ์์ ํ์ธํ๋ ๊ฒ์ด๋ค.
์๋ฅผ ๋ค์ด Bundle ํ์ผ์ master ๋ธ๋์น๋ฅผ ์์
ํ๋ ์ ์ฅ์์ 'other-master' ๋ธ๋์น๋ก ๊ฐ์ ธ์ค๋ ๋ช
๋ น์ ์๋์ ๊ฐ์ด ์คํํ๋ค.
$ git fetch ../commits.bundle master:other-master
From ../commits.bundle
* [new branch] master -> other-master์ด๋ฐ ์์ผ๋ก ์์ ํ๋ ์ ์ฅ์์ 'master' ๋ธ๋์น์ ์ด๋ค ์์ ์ ํ๋ ์๊ด์์ด Bundle ํ์ผ๋ก๋ถํฐ ์ปค๋ฐ์ ๋ ๋ฆฝ์ ์ผ๋ก 'other-master' ๋ธ๋์น๋ก ๊ฐ์ ธ์ฌ ์ ์๋ค.
$ git log --oneline --decorate --graph --all
* 8255d41 (HEAD, master) third commit - first repo
| * 71b84da (other-master) last commit - second repo
| * c99cf5b fourth commit - second repo
| * 7011d3d third commit - second repo
|/
* 9a466c5 second commit
* b1ec324 first commitgit bundle ๋ช
๋ น์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์ ์กํ ๋คํธ์ํฌ ์ํฉ์ด ์ฌ์์น ์๊ฑฐ๋ ์ฝ๊ฒ ๊ณต์ ํ ์ ์๋ ์ ์ฅ์๋ฅผ ์ค๋นํ๊ธฐ ์ด๋ ค์ธ ๋๋ ํ์คํ ๋ฆฌ๋ฅผ ์ฝ๊ฒ ๊ณต์ ํ ์ ์๋ค.