官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 九江市| 廉江市| 灌云县| 珠海市| 邵东县| 沽源县| 黑水县| 阳信县| 铜陵市| 尖扎县| 铜鼓县| 托克逊县| 云龙县| 濮阳市| 房产| 海阳市| 紫阳县| 朝阳市| 太康县| 当阳市| 平定县| 乌兰浩特市| 千阳县| 泊头市| 梨树县| 高雄县| 峡江县| 富锦市| 沈阳市| 和田县| 九寨沟县| 伊吾县| 津市市| 霞浦县| 静安区| 民县| 花莲市| 平安县| 瓮安县| 邵武市| 临城县|