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/refs.asc
+13-14Lines changed: 13 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
[[_git_refs]]
2
2
=== Git References
3
3
4
-
You can run something like `git log 1a410e` to look through your whole history, but you still have to remember that `1a410e` is the last commit in order to walk that history to find all those objects.
5
-
You need a file in which you can store the SHA-1 value under a simple name so you can use that pointer rather than the raw SHA-1 value.
4
+
If you were interested in seeing the history of your repository reachable from commit, say, `1a410e`, you could run something like `git log 1a410e` to display that history, but you would still have to remember that `1a410e` is the commit you want to use as the starting point for that history.
5
+
Instead, it would be easier if you had a file in which you could store that SHA-1 value under a simple name so you could use that simple name rather than the raw SHA-1 value.
6
6
7
-
In Git, these are called ``references'' or ``refs''; you can find the files that contain the SHA-1 values in the `.git/refs` directory.
7
+
In Git, these simple names are called ``references'' or ``refs''; you can find the files that contain those SHA-1 values in the `.git/refs` directory.
8
8
In the current project, this directory contains no files, but it does contain a simple structure:
9
9
10
10
[source,console]
@@ -33,8 +33,7 @@ cac0cab538b970a37ea1e769cbbde608743bc96d second commit
33
33
fdf4fc3344e67ab068f836878b6c4951e3b15f3d first commit
34
34
----
35
35
36
-
You aren't encouraged to directly edit the reference files.
37
-
Git provides a safer command to do this if you want to update a reference called `update-ref`:
36
+
You aren't encouraged to directly edit the reference files; instead, Git provides the safer command `git update-ref` to do this if you want to update a reference:
38
37
39
38
[source,console]
40
39
----
@@ -91,7 +90,7 @@ ref: refs/heads/test
91
90
92
91
When you run `git commit`, it creates the commit object, specifying the parent of that commit object to be whatever SHA-1 value the reference in HEAD points to.
93
92
94
-
You can also manually edit this file, but again a safer command exists to do so: `symbolic-ref`.
93
+
You can also manually edit this file, but again a safer command exists to do so: `git symbolic-ref`.
95
94
You can read the value of your HEAD via this command:
96
95
97
96
[source,console]
@@ -100,7 +99,7 @@ $ git symbolic-ref HEAD
100
99
refs/heads/master
101
100
----
102
101
103
-
You can also set the value of HEAD:
102
+
You can also set the value of HEAD using the same command:
104
103
105
104
[source,console]
106
105
----
@@ -119,10 +118,10 @@ fatal: Refusing to point HEAD outside of refs/
119
118
120
119
==== Tags
121
120
122
-
We just finished discussing Git's three main object types, but there is a fourth.
123
-
The _tag_ object is very much like a commit object – it contains a tagger, a date, a message, and a pointer.
121
+
We just finished discussing Git's three main object types (_blobs_, _trees_ and _commits_), but there is a fourth.
122
+
The _tag_ object is very much like a commit object -- it contains a tagger, a date, a message, and a pointer.
124
123
The main difference is that a tag object generally points to a commit rather than a tree.
125
-
It's like a branch reference, but it never moves – it always points to the same commit but gives it a friendlier name.
124
+
It's like a branch reference, but it never moves -- it always points to the same commit but gives it a friendlier name.
126
125
127
126
As discussed in <<_git_basics_chapter>>, there are two types of tags: annotated and lightweight.
128
127
You can make a lightweight tag by running something like this:
@@ -132,10 +131,10 @@ You can make a lightweight tag by running something like this:
That is all a lightweight tag is – a reference that never moves.
134
+
That is all a lightweight tag is -- a reference that never moves.
136
135
An annotated tag is more complex, however.
137
136
If you create an annotated tag, Git creates a tag object and then writes a reference to point to it rather than directly to the commit.
138
-
You can see this by creating an annotated tag (`-a` specifies that it's an annotated tag):
137
+
You can see this by creating an annotated tag (using the `-a` option):
139
138
140
139
[source,console]
141
140
----
@@ -150,7 +149,7 @@ $ cat .git/refs/tags/v1.1
150
149
9585191f37f7b0fb9444f35a9bf50de191beadc2
151
150
----
152
151
153
-
Now, run the `cat-file` command on that SHA-1 value:
152
+
Now, run `git cat-file -p` on that SHA-1 value:
154
153
155
154
[source,console]
156
155
----
@@ -173,7 +172,7 @@ You can view the public key by running this in a clone of the Git repository:
173
172
$ git cat-file blob junio-gpg-pub
174
173
----
175
174
176
-
The Linux kernel repository also has a non-commit-pointing tag object – the first tag created points to the initial tree of the import of the source code.
175
+
The Linux kernel repository also has a non-commit-pointing tag object -- the first tag created points to the initial tree of the import of the source code.
0 commit comments