Skip to content

Commit

Permalink
Merge pull request #917 from rpjday/references
Browse files Browse the repository at this point in the history
More minor tweaks and rewording for "Git References" section
  • Loading branch information
ben authored Nov 4, 2017
2 parents ec2a0c7 + f0ad3ac commit 01e2225
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions book/10-git-internals/sections/refs.asc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[[_git_refs]]
=== Git References

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.
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.
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.
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.

In Git, these are called ``references'' or ``refs''; you can find the files that contain the SHA-1 values in the `.git/refs` directory.
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.
In the current project, this directory contains no files, but it does contain a simple structure:

[source,console]
Expand Down Expand Up @@ -33,8 +33,7 @@ cac0cab538b970a37ea1e769cbbde608743bc96d second commit
fdf4fc3344e67ab068f836878b6c4951e3b15f3d first commit
----

You aren't encouraged to directly edit the reference files.
Git provides a safer command to do this if you want to update a reference called `update-ref`:
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:

[source,console]
----
Expand Down Expand Up @@ -91,7 +90,7 @@ ref: refs/heads/test

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.

You can also manually edit this file, but again a safer command exists to do so: `symbolic-ref`.
You can also manually edit this file, but again a safer command exists to do so: `git symbolic-ref`.
You can read the value of your HEAD via this command:

[source,console]
Expand All @@ -100,7 +99,7 @@ $ git symbolic-ref HEAD
refs/heads/master
----

You can also set the value of HEAD:
You can also set the value of HEAD using the same command:

[source,console]
----
Expand All @@ -119,10 +118,10 @@ fatal: Refusing to point HEAD outside of refs/

==== Tags

We just finished discussing Git's three main object types, but there is a fourth.
The _tag_ object is very much like a commit object it contains a tagger, a date, a message, and a pointer.
We just finished discussing Git's three main object types (_blobs_, _trees_ and _commits_), but there is a fourth.
The _tag_ object is very much like a commit object -- it contains a tagger, a date, a message, and a pointer.
The main difference is that a tag object generally points to a commit rather than a tree.
It's like a branch reference, but it never moves it always points to the same commit but gives it a friendlier name.
It's like a branch reference, but it never moves -- it always points to the same commit but gives it a friendlier name.

As discussed in <<_git_basics_chapter>>, there are two types of tags: annotated and lightweight.
You can make a lightweight tag by running something like this:
Expand All @@ -132,10 +131,10 @@ You can make a lightweight tag by running something like this:
$ git update-ref refs/tags/v1.0 cac0cab538b970a37ea1e769cbbde608743bc96d
----

That is all a lightweight tag is a reference that never moves.
That is all a lightweight tag is -- a reference that never moves.
An annotated tag is more complex, however.
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.
You can see this by creating an annotated tag (`-a` specifies that it's an annotated tag):
You can see this by creating an annotated tag (using the `-a` option):

[source,console]
----
Expand All @@ -150,7 +149,7 @@ $ cat .git/refs/tags/v1.1
9585191f37f7b0fb9444f35a9bf50de191beadc2
----

Now, run the `cat-file` command on that SHA-1 value:
Now, run `git cat-file -p` on that SHA-1 value:

[source,console]
----
Expand All @@ -173,7 +172,7 @@ You can view the public key by running this in a clone of the Git repository:
$ git cat-file blob junio-gpg-pub
----

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.
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.

==== Remotes

Expand Down

0 comments on commit 01e2225

Please sign in to comment.