You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/10-git-internals/sections/objects.asc
+19-19Lines changed: 19 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -111,7 +111,7 @@ version 2
111
111
112
112
But remembering the SHA-1 key for each version of your file isn't practical; plus, you aren't storing the filename in your system -- just the content.
113
113
This object type is called a _blob_.
114
-
You can have Git tell you the object type of any object in Git, given its SHA-1 key, with `cat-file -t`:
114
+
You can have Git tell you the object type of any object in Git, given its SHA-1 key, with `git cat-file -t`:
115
115
116
116
[source,console]
117
117
----
@@ -122,7 +122,7 @@ blob
122
122
[[_tree_objects]]
123
123
==== Tree Objects
124
124
125
-
The next type we'll look at is the _tree_, which solves the problem of storing the filename and also allows you to store a group of files together.
125
+
The next type of Git object we'll examine is the _tree_, which solves the problem of storing the filename and also allows you to store a group of files together.
126
126
Git stores content in a manner similar to a UNIX filesystem, but a bit simplified.
127
127
All the content is stored as tree and blob objects, with trees corresponding to UNIX directory entries and blobs corresponding more or less to inodes or file contents.
128
128
A single tree object contains one or more tree entries, each of which contains a SHA-1 pointer to a blob or subtree with its associated mode, type, and filename.
Conceptually, the data that Git is storing is something like this:
148
+
Conceptually, the data that Git is storing looks something like this:
149
149
150
150
.Simple version of the Git data model.
151
151
image::images/data-model-1.png[Simple version of the Git data model.]
152
152
153
153
You can fairly easily create your own tree.
154
154
Git normally creates a tree by taking the state of your staging area or index and writing a series of tree objects from it.
155
155
So, to create a tree object, you first have to set up an index by staging some files.
156
-
To create an index with a single entry – the first version of your `test.txt` file – you can use the plumbing command `update-index`.
156
+
To create an index with a single entry -- the first version of your `test.txt` file -- you can use the plumbing command `git update-index`.
157
157
You use this command to artificially add the earlier version of the `test.txt` file to a new staging area.
158
158
You must pass it the `--add` option because the file doesn't yet exist in your staging area (you don't even have a staging area set up yet) and `--cacheinfo` because the file you're adding isn't in your directory but is in your database.
In this case, you're specifying a mode of `100644`, which means it's a normal file.
168
168
Other options are `100755`, which means it's an executable file; and `120000`, which specifies a symbolic link.
169
-
The mode is taken from normal UNIX modes but is much less flexible – these three modes are the only ones that are valid for files (blobs) in Git (although other modes are used for directories and submodules).
169
+
The mode is taken from normal UNIX modes but is much less flexible -- these three modes are the only ones that are valid for files (blobs) in Git (although other modes are used for directories and submodules).
170
170
171
-
Now, you can use the `write-tree` command to write the staging area out to a tree object.
172
-
No `-w` option is needed – calling `write-tree` automatically creates a tree object from the state of the index if that tree doesn't yet exist:
171
+
Now, you can use `git write-tree` to write the staging area out to a tree object.
172
+
No `-w` option is needed -- calling this command automatically creates a tree object from the state of the index if that tree doesn't yet exist:
Notice that this tree has both file entries and also that the `test.txt` SHA-1 is the ``version 2'' SHA-1 from earlier (`1f7a7a`).
213
213
Just for fun, you'll add the first tree as a subdirectory into this one.
214
-
You can read trees into your staging area by calling `read-tree`.
215
-
In this case, you can read an existing tree into your staging area as a subtree by using the `--prefix` option to `read-tree`:
214
+
You can read trees into your staging area by calling `git read-tree`.
215
+
In this case, you can read an existing tree into your staging area as a subtree by using the `--prefix` option with this command:
216
216
217
217
[source,console]
218
218
----
@@ -234,7 +234,7 @@ image::images/data-model-2.png[The content structure of your current Git data.]
234
234
[[_git_commit_objects]]
235
235
==== Commit Objects
236
236
237
-
You have three trees that specify the different snapshots of your project that you want to track, but the earlier problem remains: you must remember all three SHA-1 values in order to recall the snapshots.
237
+
If you've done all of the above, you now have three trees that represent the different snapshots of your project that you want to track, but the earlier problem remains: you must remember all three SHA-1 values in order to recall the snapshots.
238
238
You also don't have any information about who saved the snapshots, when they were saved, or why they were saved.
239
239
This is the basic information that the commit object stores for you.
You've just done the low-level operations to build up a Git history without using any of the front end commands.
313
-
This is essentially what Git does when you run the `git add` and `git commit` commands – it stores blobs for the files that have changed, updates the index, writes out trees, and writes commit objects that reference the top-level trees and the commits that came immediately before them.
314
-
These three main Git objects – the blob, the tree, and the commit – are initially stored as separate files in your `.git/objects` directory.
313
+
This is essentially what Git does when you run the `git add` and `git commit` commands -- it stores blobs for the files that have changed, updates the index, writes out trees, and writes commit objects that reference the top-level trees and the commits that came immediately before them.
314
+
These three main Git objects -- the blob, the tree, and the commit -- are initially stored as separate files in your `.git/objects` directory.
315
315
Here are all the objects in the example directory now, commented with what they store:
316
316
317
317
[source,console]
@@ -336,9 +336,9 @@ image::images/data-model-3.png[All the reachable objects in your Git directory.]
336
336
337
337
==== Object Storage
338
338
339
-
We mentioned earlier that a header is stored with the content.
340
-
Let's take a minute to look at how Git stores its objects.
341
-
You'll see how to store a blob object – in this case, the string ``what is up, doc?'' – interactively in the Ruby scripting language.
339
+
We mentioned earlier that there is a header stored with every object you commit to your Git object database.
340
+
Let's take a minute to see how Git stores its objects.
341
+
You'll see how to store a blob object -- in this case, the string ``what is up, doc?'' -- interactively in the Ruby scripting language.
342
342
343
343
You can start up interactive Ruby mode with the `irb` command:
344
344
@@ -349,8 +349,8 @@ $ irb
349
349
=> "what is up, doc?"
350
350
----
351
351
352
-
Git constructs a header that starts with the type of the object, in this case a blob.
353
-
Then, it adds a space followed by the size of the content and finally a null byte:
352
+
Git first constructs a header which starts by identifying the type of object -- in this case, a blob.
353
+
To that first part of the header, Git adds a space followed by the size in bytes of the content, and adding a final null byte:
0 commit comments