LoginSignup
11
7

More than 5 years have passed since last update.

git unpack-objectsの紹介

Posted at

普通に生活していたら使う日は絶対に来ないであろう、超絶マニアックコマンドgit unpack-objectsを紹介します。

git unpack-objects とは何か?

Gitレポジトリの圧縮データベースであるpack file (.git/objects/pack/pack-***.pack みたいなやつ) を展開して、多数のloose object( .git/objects/1a/0480f.. みたいなやつ)ファイルにばらしてくれます。

何が嬉しいかと言うと、Gitの内部構造の研究をしていてloose objectがたくさん欲しいときに便利です。
つまり俺得です。(笑)

注意点

ただし落とし穴があって、既にそのレポジトリ内にオブジェクトが(pack/loose問わず)存在している場合は展開してくれません。
簡単に言うと、1つのレポジトリ内でこのコマンドを使っても何も起きないのです。

 Objects that already exist in the repository will not be unpacked from the pack-file. Therefore, nothing will be unpacked if you use this command on a
       pack-file that exists within the target repository.
git clone git://github.com/DQNEO/ethnam.git
cd ethnam
git unpack-objects  < .git/objects/pack/pack-c3675fd09b61cfd7f0e8fc9c9e547f972e0342f5.pack
# 何も起きない!

レポジトリをまたいで使えばOK

ポイントは、packファイルを標準入力で受け取ることです。つまり別のレポジトリからpackファイルを受け取ることができます。

例えばレポジトリを新規作成して、そこにpackファイルの中身を展開したりできます。

cd /tmp
git init newrepo
cd newrepo
git unpack-objects  < ~/ethnam/.git/objects/pack/pack-c3675fd09b61cfd7f0e8fc9c9e547f972e0342f5.pack
# ethnamのpackファイル内の全オブジェクトが、newrepo内に展開される。
ls .git/objects
00/  08/  10/  18/  20/  28/  30/  38/  40/  48/  50/  58/  60/  68/  70/  78/  80/  88/  90/  98/  a0/  a8/  b0/  b8/  c0/  c8/  d0/  d8/  e0/  e8/  f0/  f8/  info/
01/  09/  11/  19/  21/  29/  31/  39/  41/  49/  51/  59/  61/  69/  71/  79/  81/  89/  91/  99/  a1/  a9/  b1/  b9/  c1/  c9/  d1/  d9/  e1/  e9/  f1/  f9/  pack/
02/  0a/  12/  1a/  22/  2a/  32/  3a/  42/  4a/  52/  5a/  62/  6a/  72/  7a/  82/  8a/  92/  9a/  a2/  aa/  b2/  ba/  c2/  ca/  d2/  da/  e2/  ea/  f2/  fa/
03/  0b/  13/  1b/  23/  2b/  33/  3b/  43/  4b/  53/  5b/  63/  6b/  73/  7b/  83/  8b/  93/  9b/  a3/  ab/  b3/  bb/  c3/  cb/  d3/  db/  e3/  eb/  f3/  fb/
04/  0c/  14/  1c/  24/  2c/  34/  3c/  44/  4c/  54/  5c/  64/  6c/  74/  7c/  84/  8c/  94/  9c/  a4/  ac/  b4/  bc/  c4/  cc/  d4/  dc/  e4/  ec/  f4/  fc/
05/  0d/  15/  1d/  25/  2d/  35/  3d/  45/  4d/  55/  5d/  65/  6d/  75/  7d/  85/  8d/  95/  9d/  a5/  ad/  b5/  bd/  c5/  cd/  d5/  dd/  e5/  ed/  f5/  fd/
06/  0e/  16/  1e/  26/  2e/  36/  3e/  46/  4e/  56/  5e/  66/  6e/  76/  7e/  86/  8e/  96/  9e/  a6/  ae/  b6/  be/  c6/  ce/  d6/  de/  e6/  ee/  f6/  fe/
07/  0f/  17/  1f/  27/  2f/  37/  3f/  47/  4f/  57/  5f/  67/  6f/  77/  7f/  87/  8f/  97/  9f/  a7/  af/  b7/  bf/  c7/  cf/  d7/  df/  e7/  ef/  f7/  ff/
11
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
7