Contents of Git objects

Bogdan Stashchuk
A free video tutorial from Bogdan Stashchuk
Software Engineer, CCIE #22608, MBA, PhD -
4.7 instructor rating • 14 courses • 178,809 students

Lecture description

Every Git object has specific structure. Git stores following data in every object: type, length, delimiter and content.

Learn more from the full course

Complete Git Guide: Understand and master Git and GitHub

Complete Git and GitHub guide (22 HOURS) - Master all Git features: commits, branches, merging, rebasing and squashing

23:05:20 of on-demand video • Updated March 2021

  • Deeply understand how Git works under the hood
  • Use Git not just in terminal but also in graphical user interfaces like GitHub Desktop, SourceTree, Visual Studio Code
  • Learn different GIt objects - blobs, trees, commits and annotated tags
  • Create local and remote Git repositories
  • Perform basic and advanced Git operations
  • Learn how to perform rebasing and merging of the branches
  • Learn what is pull request and how to create pull request at GitHub
  • Contribute to public repositories using technique of forks and pull requests from the forked repository
  • Understand what is semantic versioning and how to use Git Tags in order to create software release versions
  • Learn advanced Git operations - squashing, cherry-picking, amending, reverting commits.
English [Auto] We have just discussed that get blobs don't store name of the file that was used as source for creation of GID blob. Also we have discussed that the object type and object length are stored inside of the block. And now it's a good time to explain the structure of every good object get object consists of four fields object type object landmarks delimiter and content and he'll use the example of the blob here object type is blob object length is glove on. He you see delimiter it is actually null character and does all we've done as backslash 0 and after that comes content and in our database in our first project we have such object Diablo Verb Object length is alignment and content cholo get and it doesn't matter how does. Object is created there are always only four fields inside of actual get object in the database how can we prove that there are two ways. Thrust is to read contents of get object directly and second by creating SHA 1 hash or for those contents and comparing resulting cache with the hash that was generated by get hash object command in our case this cache but let's throw it away to read contents or get object directly and let do that here in the terminal let's clear terminal and let's see d to dot get slash objects let's list files here. Alas dash L.A. And here now we see two folders for two files forty four and b seven and less for example C DB to folder 44 and inside of this folder unless does L.A. I'll see only one file this one and let's not try to read contents of this file using God command please note not you've got file comment just got come and got and name of the file 0 0 and I 0 breast stamp here and press enter and I see nothing here in the output. The reason is simple get stores files in compressed binary format and that's why we're not able to read them directly in such a way but if you want to read the contents of get object you can install Python and use Zilly utility in order to uncompressed specific get object I will show you that and we will use second way to verify that the structure all for good object is like this and for that let's use just some utility and generate shot one hash based on all those contents on those four fields let's go back to terminal and let me open new tab come on to you and here let's write following extreme echo double quotes blob then space then eleven eleven is a size then backslash zero it is now a character and after that without space hello come up did and glows in double quotes let's press enter and here in the time no I see this tweak blow up space eleven without escape character Hello. Come on get and let's try to generate shop one hash from this stream. Let's go to historian at five here and they've simply shot some rock up the scope of pipe. We can direct output of this comment to next comment. In our case shot some less press enter and here shot some gets generated us shot one hash from this screen and this shot one hash Luke spread is similar to the show on a hash of the object that we have already created. If I will get back to this step and scroll off to the place where we can create this object. This one we see this hash it starts with B 7 and adds was 5 e and this cache exactly matches D cache and that means that it has used those gauntlets for generation of shot one cast and that proves that gift stores such object in its database and each object has object type object lengths the limiter and contents of the object please note that if you use ores or shell not item with z h you might get as a result here. And the reason for that may be different interpretation of these escaped character backslash 0 null character and in order to tell Shell that the ID should interpret escaped characters you should add another option to a command. Let's go back to his story. Go tell a to the beginning of the line and here at option dash e and in our case if I left press enter enter. I'll get the same result as before and if I try to generate cash shore some cash with this option. Dash e. I'll get same result answer and same result as here. But if I'll open built in time and no let's do that I mean no answer. And let me make it larger and type. Same comment echo. Double walls. Blow up space eleven backslash zero. Hello. Come on. Get and at here pipe and shot some enter. I'll get a NAS or crash but if i'll add dash e option let me do that here. Dash e and for us enter I'll get desired result this because in Terminal E failed just entered this command let me copy it and based here I'll see escaped characters here. And that means that this escaped character wasn't interpreted by best shell and if I want to interpret it I'll need to add here dash e option. That's it Andrew. And no I'll get swing without escaped character but it doesn't mean that escape character was simply deleted. It is here but we simply don't see it. If it glows this time no window and back to item and try to generate SHA 1 cash without this escaped character like this and press enter. I'll get different cache but if I'll bring to terminal result of this command like this you'll see the same string as here but again in this case escaped character is here. But it does hit them and in this case there was no escaped character may sound difficult but that's how it works under the hood. Okay. Summary from this lecture is that each get object has such structure it contains object type object lengths delimiter and content of each object. And no small task for you please try to generate some cash for it. Object as looks in database for our NAS or a screen recap. There are two files in the database and the contents of second file are here. Second file in the repository. So task for you. Please try to generate SHA 1 to pass for this get object using shot some utility. And compare result usually get this short on cash. I wish you good luck okay. Let's quickly do the together. Here was text for the object here was type of the object blob. And here was in size. We didn't simply combine all those three inputs. Let's go back to this step. Let me clear it and type here. Following echo. Let's add dash e option for interpretation of escaped characters then double golds and first comes type of the object. Now our case does block then a space. After that comes the size and size of this object is sorted Let's type sorta backslash 0 escaped character now and after that comes string. In our case this drink is here. Second file in the repository. Let's copy it and paste here without any spaces let's at closing double quotes and that's where you fi where's our. Everything is fine let's press Enter now and here we see this tweak in time and null without escaped character but again it is there. Let's get back to history at his pipe and dive shop. Some enter and here was a result. And this short on cash matches this short on cash okay. I hope that you enjoyed this lecture and now you know how good stores objects in its database every object is thought along with its type lengths and believe it or okay. That's all for this lecture and the next one. Let's find out how to read file names for the blogs and I think that you could get an answer. File names for the blogs would be stored in trees and tree is an order object type indeed. Let's talk about it in the next lecture. I'll see you there. Bye bye.