Skip to content

Commit 3f0242e

Browse files
authored
Merge pull request #913 from rpjday/objects
Tweaks (grammar/sentence structure) to first part of "Git Objects"
2 parents 3cf6874 + 1c5fa82 commit 3f0242e

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

book/10-git-internals/sections/objects.asc

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ Git is a content-addressable filesystem.
55
Great.
66
What does that mean?
77
It means that at the core of Git is a simple key-value data store.
8-
You can insert any kind of content into it, and it will give you back a key that you can use to retrieve the content again at any time.
9-
To demonstrate, you can use the plumbing command `hash-object`, which takes some data, stores it in your `.git/objects` directory (the _object database_), and gives you back the key the data is stored as.
8+
What this means it that you can insert any kind of content into a Git repository, for which Git will hand you back a unique key you can use later to retrieve that content.
109

11-
First, you initialize a new Git repository and verify that there is nothing in the `objects` directory:
10+
As a demonstration, let's look at the plumbing command `git hash-object`, which takes some data, stores it in your `.git/objects` directory (the _object database_), and gives you back the unique key that now refers to that data object.
11+
12+
First, you initialize a new Git repository and verify that there is (predictably) nothing in the `objects` directory:
1213

1314
[source,console]
1415
----
@@ -23,18 +24,20 @@ $ find .git/objects -type f
2324
----
2425

2526
Git has initialized the `objects` directory and created `pack` and `info` subdirectories in it, but there are no regular files.
26-
Now, store some text in your Git database:
27+
Now, let's use `git hash-object` to create a new data object and manually store it in your new Git database:
2728

2829
[source,console]
2930
----
3031
$ echo 'test content' | git hash-object -w --stdin
3132
d670460b4b4aece5915caf5c68d12f560a9fe3e4
3233
----
3334

34-
The `-w` tells `hash-object` to store the object; otherwise, the command simply tells you what the key would be.
35-
`--stdin` tells the command to read the content from stdin; if you don't specify this, `hash-object` expects a file path at the end.
36-
The output from the command is a 40-character checksum hash.
37-
This is the SHA-1 hash – a checksum of the content you're storing plus a header, which you'll learn about in a bit.
35+
In its simplest form, `git hash-object` would take the content you handed to it and merely return the unique key that _would_ be used to store it in your Git database.
36+
The `-w` option then tells the command to not simply return the key, but to write that object to the database.
37+
Finally, the `--stdin` option tells `git hash-object` to get the content to be processed from stdin; otherwise, the command would expect a filename argument at the end of the command containing the content to be used.
38+
39+
The output from the above command is a 40-character checksum hash.
40+
This is the SHA-1 hash -- a checksum of the content you're storing plus a header, which you'll learn about in a bit.
3841
Now you can see how Git has stored your data:
3942

4043
[source,console]
@@ -43,13 +46,13 @@ $ find .git/objects -type f
4346
.git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4
4447
----
4548

46-
You can see a file in the `objects` directory.
47-
This is how Git stores the content initially as a single file per piece of content, named with the SHA-1 checksum of the content and its header.
49+
If you again examine your `objects` directory, you can see that it now contains a file for that new content.
50+
This is how Git stores the content initially -- as a single file per piece of content, named with the SHA-1 checksum of the content and its header.
4851
The subdirectory is named with the first 2 characters of the SHA-1, and the filename is the remaining 38 characters.
4952

50-
You can pull the content back out of Git with the `cat-file` command.
53+
Once you have content in your object database, you can examine that content with the `git cat-file` command.
5154
This command is sort of a Swiss army knife for inspecting Git objects.
52-
Passing `-p` to it instructs the `cat-file` command to figure out the type of content and display it nicely for you:
55+
Passing `-p` to `cat-file` instructs the command to first figure out the type of content, then display it appropriately:
5356

5457
[source,console]
5558
----
@@ -78,7 +81,7 @@ $ git hash-object -w test.txt
7881
1f7a7a472abf3dd9643fd615f6da379c4acb3e3a
7982
----
8083

81-
Your database contains the two new versions of the file as well as the first content you stored there:
84+
Your object database now contains both versions of this new file (as well as the first content you stored there):
8285

8386
[source,console]
8487
----
@@ -88,7 +91,7 @@ $ find .git/objects -type f
8891
.git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4
8992
----
9093

91-
Now you can revert the file back to the first version
94+
At this point, you can delete your local copy of that `test.txt` file, then use Git to retrieve, from the object database, either the first version you saved:
9295

9396
[source,console]
9497
----
@@ -106,7 +109,7 @@ $ cat test.txt
106109
version 2
107110
----
108111

109-
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.
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.
110113
This object type is called a _blob_.
111114
You can have Git tell you the object type of any object in Git, given its SHA-1 key, with `cat-file -t`:
112115

0 commit comments

Comments
 (0)