Download Scott Chacon

Transcript
C H A P T E R 9 N G I T I N T E R N A LS
file called a packfile in order to save space and be more efficient. Git does this if you have
too many loose objects around, if you run the cepc_ command manually, or if you push to
a remote server. To see what happens, you can manually ask Git to pack up the objects by calling the cepc_ command:
cepc_
?kqjpejck^fa_po6-3(`kja*
@ahp]_kilnaooekjqoejc.pdna]`o*
?kilnaooejck^fa_po6-,,!$-/+-/%(`kja*
Snepejck^fa_po6-,,!$-3+-3%(`kja*
Pkp]h-3$`ahp]-%(naqoa`-,$`ahp],%
If you look in your k^fa_po directory, you’ll find that most of your objects are gone, and
a new pair of files has appeared:
bej`*cep+k^fa_po)pulab
*cep+k^fa_po+3-+,4b3a_^/01aa5`,,40-5/b-03_`]`0`.554.5/
*cep+k^fa_po+`2+3,02,^0^0]a_a15-1_]b1_24`-.b12,]5ba/a0
*cep+k^fa_po+ejbk+l]_go
*cep+k^fa_po+l]_g+l]_g)3]-2a0044]a0,_3`.^_12a].^`0/a.1.-.]22_01*e`t
*cep+k^fa_po+l]_g+l]_g)3]-2a0044]a0,_3`.^_12a].^`0/a.1.-.]22_01*l]_g
The objects that remain are the blobs that aren’t pointed to by any commit—in this
case, the “what is up, doc?” example and the “test content” example blobs you created earlier. Because you never added them to any commits, they’re considered dangling and aren’t
packed up in your new packfile.
The other files are your new packfile and an index. The packfile is a single file containing
the contents of all the objects that were removed from your filesystem. The index is a file that
contains offsets into that packfile so you can quickly seek to a specific object. What is cool is
that although the objects on disk before you ran the c_ were collectively about 12K in size, the
new packfile is only 6K. You’ve halved your disk usage by packing your objects.
How does Git do this? When Git packs objects, it looks for files that are named and sized
similarly, and stores just the deltas from one version of the file to the next. You can look into
the packfile and see what Git did to save space. The cepranebu)l]_g plumbing command
allows you to see what was packed up:
cepranebu)l]_g)rl]_g)3]-2a0044]a0,_3`.^_12a].^`0/a.1.-.]22_01*e`t
,-11a^0..541-2/0],b,/a^.21^25b1].`12b/0-pnaa3-3210,,
,10,4`-51.2/`41/b,5`_]3-`11--222/25,_.3_^hk^-.5,4/034430
,5b,-_a]103222b14`2]4`4,514/40-]3_2b,-/,pnaa-,2-,31,42
-]0-,ab^`-/15-`^,30522,-a^_3],15``11_ba5_kiiep..1-1-/..
-b3]3]03.]^b/``520/b`2-1b2`]/35_0]_^/a/]^hk^-,-51/4/_0a5_`345`44`4`45_-,3/3,3_/141a0-^,a2-0pnaa-,--,11.-040]15.31,/-5,5a-5]]`^3_5..2.3-5_b_`b-5]_kiiep..2-1/-25
4/^]]a2-4,0a21__3/]3.,-]3.1.31,_32,22]/,^hk^-,-51/2.
5141-5-b/3b3^,b^5000b/1]5^b1,`a-5-^a]`_.p]c-/2-.31032
5^_-`_0.-`_`1-^0]_.52a/a1^2a.]55_b00/5-a^hk^3-41-5/-±
,10,4`-51.2/`41/b,5`_]3-`11--222/25,_.3_
]^-]bab4,b]_4a/0.14bb0-b_-^423_3,.`]].0^_kiiep./.-13-.
_]_,_]^1/4^53,]/3a]-a325_^^`a2,430/^_52`_kiiep..2-1003/
237