|
| 1 | + |
| 2 | +常用的 git 说明见 [git 使用说明](./git.md) 。本文记录一些底层 git 技术。 |
| 3 | + |
| 4 | +### clone 本地仓库 |
| 5 | +```bash |
| 6 | +$ git clone /home/git/repositories/801/038/000/38801.git |
| 7 | +``` |
| 8 | + |
| 9 | +### 查看object文件的内容 |
| 10 | +使用 `git cat-file` 可以查看 `object` 文件的内容,但是查看的内容是转换过的: |
| 11 | + |
| 12 | +```bash |
| 13 | +$ git cat-file -p aa548c4d7910229712ba3a41e74c6db872e8ab64 |
| 14 | +100644 blob c30106543ed8f32af334362fa82e3a4ad71ef20f home.md |
| 15 | +``` |
| 16 | + |
| 17 | +可以使用 [zlib-flate](http://manpages.ubuntu.com/manpages/trusty/man1/zlib-flate.1.html) 命令解压看到真实内容: |
| 18 | + |
| 19 | +```bash |
| 20 | +$ zlib-flate -uncompress < .git/objects/aa/548c4d7910229712ba3a41e74c6db872e8ab64 | hexdump -C |
| 21 | +00000000 74 72 65 65 20 33 35 00 31 30 30 36 34 34 20 68 |tree 35.100644 h| |
| 22 | +00000010 6f 6d 65 2e 6d 64 00 c3 01 06 54 3e d8 f3 2a f3 |ome.md....T>..*.| |
| 23 | +00000020 34 36 2f a8 2e 3a 4a d7 1e f2 0f |46/..:J....| |
| 24 | +0000002b |
| 25 | +``` |
| 26 | + |
| 27 | +> tree 对象 文件格式请看:[tree 对象](https://juejin.im/post/6874840619332665357#heading-16)。 |
| 28 | +> 需要安装 qpdf 才能正常使用 [zlib-flate](http://manpages.ubuntu.com/manpages/trusty/man1/zlib-flate.1.html) 命令:`apt install qpdf` 。 |
| 29 | +
|
| 30 | +### git cat-file |
| 31 | +查看objects文件。 |
| 32 | +**说明** |
| 33 | +```bash |
| 34 | +usage: git cat-file (-t [--allow-unknown-type] | -s [--allow-unknown-type] | -e | -p | <type> | --textconv | --filters) [--path=<path>] <object> |
| 35 | + or: git cat-file (--batch | --batch-check) [--follow-symlinks] [--textconv | --filters] |
| 36 | + |
| 37 | +<type> can be one of: blob, tree, commit, tag |
| 38 | + -t show object type |
| 39 | + -s show object size |
| 40 | + -e exit with zero when there's no error |
| 41 | + -p pretty-print object's content |
| 42 | + --textconv for blob objects, run textconv on object's content |
| 43 | + --filters for blob objects, run filters on object's content |
| 44 | + --path <blob> use a specific path for --textconv/--filters |
| 45 | + --allow-unknown-type allow -s and -t to work with broken/corrupt objects |
| 46 | + --buffer buffer --batch output |
| 47 | + --batch[=<format>] show info and content of objects fed from the standard input |
| 48 | + --batch-check[=<format>] |
| 49 | + show info about objects fed from the standard input |
| 50 | + --follow-symlinks follow in-tree symlinks (used with --batch or --batch-check) |
| 51 | + --batch-all-objects show all objects with --batch or --batch-check |
| 52 | +``` |
| 53 | +**示例** |
| 54 | +```bash |
| 55 | +# 查看objects文件类型 |
| 56 | +$ git cat-file -t 56ec1a0729533fbd8d38b7964b6f8ca2cace70ba |
| 57 | +commit |
| 58 | + |
| 59 | +# 查看objects文件大小 |
| 60 | +$ git cat-file -s 56ec1a0729533fbd8d38b7964b6f8ca2cace70ba |
| 61 | +243 |
| 62 | + |
| 63 | +# 查看objects文件(格式化)内容 |
| 64 | +$ git cat-file -p 56ec1a0729533fbd8d38b7964b6f8ca2cace70ba |
| 65 | +tree 7f9adb36c3e987d1ca9d40ba538afd8cbc74e942 |
| 66 | +parent cf22ff3d15d718603f93c36f13d848e00d841def |
| 67 | +author chenan.xxw <[email protected]> 1599545250 +0800 |
| 68 | +committer chenan.xxw <[email protected]> 1599545250 +0800 |
| 69 | + |
| 70 | +update README.md |
| 71 | + |
| 72 | +# 也可以通过 tag 或 branch 名称查看 object 文件 |
| 73 | +$ git cat-file -t v0.1.0 |
| 74 | +tag |
| 75 | +$ git cat-file -p v0.1.0 |
| 76 | +object c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc |
| 77 | +type commit |
| 78 | +tag v0.1.0 |
| 79 | +tagger Scott Chacon <[email protected]> 1290556430 -0800 |
| 80 | + |
| 81 | +tagging initial release of libgit2 |
| 82 | +``` |
0 commit comments