1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

gitリポジトリのオブジェクトデータベースをさくっとリストしてみる

Last updated at Posted at 2021-01-16

オブジェクトデータベースとは?

いいかげんgitのことをちゃんと知りたいというあなたへ(内部構造編)をご参照ください

.git/objectsの中身をさくっとみたい

.git/objectsにあるgitオブジェクトの
種類サイズ内容 を表示します。
gitリポジトリに置いて実行してみてください

ls-git-obj.sh
#!/bin/sh

GITOBJ_DIR="./.git/objects"

for path in ${GITOBJ_DIR}/*; do
    dir=`basename ${path}`
    # ディレクトリ名が2文字のものの内容を表示
    if [ ${#dir} -eq 2 ]; then
      obj_name=`find ${GITOBJ_DIR}/${dir} -type f | xargs basename`
      echo '------------------------'
      echo '- object-id:'
      echo ${dir}${obj_name}
      echo '- type:'
      git cat-file -t ${dir}${obj_name}
      echo '- size:'
      git cat-file -s ${dir}${obj_name}
      echo '- contents:'
      git cat-file -p ${dir}${obj_name}
    fi
done

実行結果はこちら

$ ./ls-git-obj.sh
------------------------
20c8a040010b6ca65a4c9d75873da6b86aff7447
- type:
commit
- size:
178
- contents:
tree a760aa994bbdd615f7ecb442be6bab636e11eba6
author: atchy <atchy@example.com> 1610805112 +0900
committer atchy <atchy@example.com> 1610805112 1610805112 +0900

add aaa.txt
------------------------
72943a16fb2c8f38f9dde202b7a70ccc19c52f34
- type:
blob
- size:
4
- contents:
aaa
------------------------
a760aa994bbdd615f7ecb442be6bab636e11eba6
- type:
tree
- size:
35
- contents:
100644 blob 72943a16fb2c8f38f9dde202b7a70ccc19c52f34	aaa.txt

もうちょっときれいに表示できんもんかなあ

1
0
1

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?