- Git Essentials(Second Edition)
- Ferdinando Santacroce
- 446字
- 2021-07-02 15:27:07
Going deeper
We analyzed a commit, and the information supplied by a simple git log; but we are not yet satisfied, so go deeper and see what's inside.
Using the git log command again, we can enable x-ray vision using the --format=raw option:
[14] ~/grocery (master) $ git log --format=raw commit a57d783905e6a35032d9b0583f052fb42d5a1308 tree a31c31cb8d7cc16eeae1d2c15e61ed7382cebf40 author Ferdinando Santacroce <ferdinando.santacroce@gmail.com> 1502970693 +0200 committer Ferdinando Santacroce <ferdinando.santacroce@gmail.com> 1502970693 +0200 Add a banana to the shopping list
This time the output format is different; we can see the author and committer, as we saw before, but in a more compact form; then there is the commit message, but something new appears: it's a tree. Please be patient, we will talk about trees in a couple of paragraphs.
What I want to show now is another command, this time a little bit more obscure; it's git cat-file -p.
Let's try this command. To make it work, we need to specify the object we want to investigate; we can use the hash of the object, our first commit in this case. You don't need to specify the entire hash, but the first five-six characters are enough for small repositories. Git is smart enough to understand what's the object even with less than the 40 characters; the minimum is four characters, and the number increases as the total amount of Git objects in the repository increases. Just to give you an idea, the Linux kernel is currently 15 million lines of code, with millions of tracked files and folders; in that Git repository[1], you need to specify 12 characters to get the right object.
When in need, I usually try typing only the first five characters; if they are not sufficient to make Git aware of the object I need, it will warn me to input a character or two more.
Back on topic; type the command, specifying the first characters of the commit's hash (a57d7 in my case):
[15] ~/grocery (master) $ git cat-file -p a57d7 tree a31c31cb8d7cc16eeae1d2c15e61ed7382cebf40 author Ferdinando Santacroce <ferdinando.santacroce@gmail.com> 1502970693 +0200 committer Ferdinando Santacroce <ferdinando.santacroce@gmail.com> 1502970693 +0200 Add a banana to the shopping list
Okay, as you can see, the output is the same of git log --format=raw.
This is not unusual in Git: there are different commands and options that end up doing the same thing; this is a common feature of Git, and it's due to its organic growth across the years. Git changed (and changes) continuously, so the developers have to guarantee some backward compatibility when introducing new commands; this is one of the side effects.
I introduced this command only to have the chance of introducing another peculiarity of Git, the separation between porcelain commands and plumbing commands.
- Hands-On Data Structures and Algorithms with Rust
- Sybase數(shù)據(jù)庫(kù)在UNIX、Windows上的實(shí)施和管理
- Microsoft Power BI數(shù)據(jù)可視化與數(shù)據(jù)分析
- 數(shù)字媒體交互設(shè)計(jì)(初級(jí)):Web產(chǎn)品交互設(shè)計(jì)方法與案例
- INSTANT Apple iBooks How-to
- HikariCP連接池實(shí)戰(zhàn)
- SQL Server 2012實(shí)施與管理實(shí)戰(zhàn)指南
- 數(shù)據(jù)庫(kù)查詢優(yōu)化器的藝術(shù):原理解析與SQL性能優(yōu)化
- Spring Boot 2.0 Cookbook(Second Edition)
- SQL進(jìn)階教程(第2版)
- 社交網(wǎng)站的數(shù)據(jù)挖掘與分析(原書第2版)
- 數(shù)據(jù)庫(kù)基礎(chǔ)與應(yīng)用
- Applying Math with Python
- 一本書讀懂區(qū)塊鏈(第2版)
- 算法設(shè)計(jì)與問題求解(第2版):計(jì)算思維培養(yǎng)