Skip to contentSkip to conversation

git-checkout.txt: improve detached HEAD documentation

PATCH In review Jay Soffian 3 participants 9 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git-checkout.txt: improve detached HEAD documentation

The detached HEAD state is a source of much confusion for users new to git. Here we try to document it better.

Reworked from http://article.gmane.org/gmane.comp.version-control.git/138440

---
Nicolas only asked me to contribute this a full year ago, not too bad. :)

 Documentation/git-checkout.txt |  108 +++++++++++++++++++++++++++++++---------
 1 files changed, 85 insertions(+), 23 deletions(-)
Documentation/git-checkout.txt +85 -23
index 880763d..21abd2a 100644
@@ -206,40 +206,102 @@ leave out at most one of `A` and `B`, in which case it defaults to `HEAD`.
 
 Detached HEAD
 -------------
+HEAD normally refers to a named branch (e.g. "master"). Meanwhile, each
+branch refers to a specific commit-id. Let's look at a repo with three
+commits and with "master" checked out:
 
-It is sometimes useful to be able to 'checkout' a commit that is
-not at the tip of one of your branches.  The most obvious
-example is to check out the commit at a tagged official release
-point, like this:
+------------
+           HEAD (refers to master)
+            v
+a---b---c  master (refers to c)
+------------
+
+When a commit is created in this state, the branch is updated to the new
+commit-id. Let's add a commit:
 
 ------------
-$ git checkout v2.6.18
+               HEAD (refers to master)
+                v
+a---b---c---d  master (refers to d)
 ------------
 
-Earlier versions of git did not allow this and asked you to
-create a temporary branch using the `-b` option, but starting from
-version 1.5.0, the above command 'detaches' your HEAD from the
-current branch and directly points at the commit named by the tag
-(`v2.6.18` in the example above).
+It is sometimes useful to be able to checkout a commit that is not at
+the tip of any named branch, or even to create a new commit that is not
+referenced by a named branch. Let's look at what happens when we
+checkout commit b:
 
-You can use all git commands while in this state.  You can use
-`git reset --hard $othercommit` to further move around, for
-example.  You can make changes and create a new commit on top of
-a detached HEAD.  You can even create a merge by using `git
-merge $othercommit`.
+------------
+$ git checkout master^^
 
-The state you are in while your HEAD is detached is not recorded
-by any branch (which is natural --- you are not on any branch).
-What this means is that you can discard your temporary commits
-and merges by switching back to an existing branch (e.g. `git
-checkout master`), and a later `git prune` or `git gc` would
-garbage-collect them.  If you did this by mistake, you can ask
-the reflog for HEAD where you were, e.g.
+   HEAD (refers to b)
+    v
+a---b---c---d  master (refers to d)
+------------
+
+Notice that HEAD now refers directly to commit b. In git terminology,
+this is known as having a detached HEAD. It means simply that HEAD
+refers to a specific commit-id, as opposed to referring to a named
+branch. Let's add a commit while HEAD is detached:
 
 ------------
-$ git log -g -2 HEAD
+     HEAD (refers to e)
+      v
+      e
+     /
+a---b---c---d  master (refers to d)
+------------
+
+We have created a new commit, but it is referenced only by HEAD. We can
+of course add yet another commit in this state:
+
+------------
+         HEAD (refers to f)
+          v
+      e---f
+     /
+a---b---c---d  master (refers to d)
+------------
+
+In fact, we can perform all the normal git operations. But, let's look
+at what happens when we then checkout master:
+
 ------------
+$ git checkout master
 
+      e---f    HEAD (refers to master)
+     /          v
+a---b---c---d  master (refers to d)
+------------
+
+It is important to realize that at this point nothing refers to commits
+e and f. Eventually these commits will be deleted by the routine git
+garbage collection process, unless we create a reference before that
+happens. If we have not yet moved away from commit f, any of these will
+create a reference to it:
+
+------------
+$ git checkout -b foo # (1)
+$ git branch foo      # (2)
+$ git tag foo         # (3)
+------------
+
+(1) creates a new branch "foo", which refers to f, and then updates HEAD
+to refer to "foo". In other words, we'll no longer be in detached HEAD
+state after (1).
+
+(2) similarly creates a new branch "foo", which refers to f, but leaves
+HEAD detached.
+
+(3) creates a new tag "foo", which refers to f, leaving HEAD detached.
+
+If we have moved away from commit f, then we must first recover its id
+(typically by using git reflog), and then we can create a reference to
+it. For example, to see the last two commits to which HEAD referred, we
+can use:
+
+------------
+$ git log -g -2 HEAD
+------------
 
 EXAMPLES
 --------
Signature · 1 line
1.7.4.1.29.g21713
#1 lore raw

Documentation/git-checkout.txt leave out at most one of `A` and `B`, in which case it defaults to `HEAD`. · line 210

Quoted 10 lines · Jay Soffian
Documentation/git-checkout.txt +2 -0
index 880763d..21abd2a 100644
@@ -206,40 +206,102 @@ leave out at most one of `A` and `B`, in which case it defaults to `HEAD`.
 
 Detached HEAD
 -------------
+HEAD normally refers to a named branch (e.g. "master"). Meanwhile, each
+branch refers to a specific commit-id. Let's look at a repo with three

s/commit-id/commit/; we don't say "commit-id" anywhere else in this document. Also, it is Ok to be loose and colloquial in the manual and it is fine to say "commit ID" from time to time, but not in this section, one of the primary purpose of which is to illustrate distinction between pointing at something that points at a commit (i.e. branch) and pointing directly at a commit (i.e. detached).

Documentation/git-checkout.txt leave out at most one of `A` and `B`, in which case it defaults to `HEAD`. · line 220

Quoted 10 lines
Documentation/git-checkout.txt +9 -0
+commits and with "master" checked out:
 
+------------
+           HEAD (refers to master)
+            v
+a---b---c  master (refers to c)
+------------
+
+When a commit is created in this state, the branch is updated to the new
+commit-id. Let's add a commit:

... updated to point the new commit. 'git commit' creates a new commit 'd', makes it a child of 'c' and moves 'master' branch to point at 'd'. HEAD also points at 'd' as the result of 'master' moving to the new commit.

I'd also suggest avoiding "Let's add" and instead be more specific (see the above example).

Documentation/git-checkout.txt leave out at most one of `A` and `B`, in which case it defaults to `HEAD`. · line 231

Quoted 10 lines
Documentation/git-checkout.txt +7 -0
 ------------
+               HEAD (refers to master)
+                v
+a---b---c---d  master (refers to d)
 ------------
 
+It is sometimes useful to be able to checkout a commit that is not at
+the tip of any named branch, or even to create a new commit that is not
+referenced by a named branch. Let's look at what happens when we
+checkout commit b:

I think it is a regression from the original text to omit mention of tags and replace the first example of the section with a more advanced use case of jumping to the middle of a branch; it is far more likely that a user would want to detach at a specific release point.

You can rectify it by tagging 'c' as a release point and detaching the HEAD at that tag without losing the clarity of the following description. While doing so, it would be better to update the labels in the illustration with s/master/master branch/ and s/[abcde]/commit &/ as well, e.g.

HEAD (refers to branch 'master')
|
V
a---b---c---d branch 'master' (refers to commit 'd')

          ^
          |
     tag 'v2.0' (refers to commit 'c')

Documentation/git-checkout.txt leave out at most one of `A` and `B`, in which case it defaults to `HEAD`. · line 236

Quoted 4 lines
Documentation/git-checkout.txt +3 -0
+------------
+$ git checkout master^^
 
+   HEAD (refers to b)

Perhaps s/refers/& directly/ to emphasize the difference in the illustration.

Documentation/git-checkout.txt leave out at most one of `A` and `B`, in which case it defaults to `HEAD`. · line 244

Quoted 8 lines
Documentation/git-checkout.txt +8 -0
+    v
+a---b---c---d  master (refers to d)
+------------
+
+Notice that HEAD now refers directly to commit b. In git terminology,
+this is known as having a detached HEAD. It means simply that HEAD
+refers to a specific commit-id, as opposed to referring to a named
+branch. Let's add a commit while HEAD is detached:

I'd suggest dropping "In git terminology,"; the reader knows that is what is being explained when he opened the documentation.

We often say "detach the HEAD from a branch", "detach the HEAD at commit 'b'", but I don't think we say "we have a detached HEAD". Same comments from a few section before apply to "commit-id" and "Let's add".

We often say "we detach HEAD at commit 'b'" and/or "we detach HEAD from the 'master' branch", to describe this state. The HEAD directly points at the commit 'b', as opposed to referring to it indirectly through the "current" branch it points at. From this state, 'git commit' will create a new commit 'e', makes it a child of 'b', and moves HEAD to directly point at it.

Quoted 12 lines
Documentation/git-checkout.txt +11 -0
+$ git checkout master
 
+      e---f    HEAD (refers to master)
+     /          v
+a---b---c---d  master (refers to d)
+------------
+
+It is important to realize that at this point nothing refers to commits
+e and f. Eventually these commits will be deleted by the routine git
+garbage collection process, unless we create a reference before that
+happens. If we have not yet moved away from commit f, any of these will
+create a reference to it:

Documentation/git-checkout.txt leave out at most one of `A` and `B`, in which case it defaults to `HEAD`. · line 290

Quoted 10 lines
Documentation/git-checkout.txt +10 -0
+
+------------
+$ git checkout -b foo # (1)
+$ git branch foo      # (2)
+$ git tag foo         # (3)
+------------
+
+(1) creates a new branch "foo", which refers to f, and then updates HEAD
+to refer to "foo". In other words, we'll no longer be in detached HEAD
+state after (1).

Somehow it feels funny to say "after (1)" in the section marked as such. "after doing so", perhaps?

Also mimick the way how git-reset.txt, everyday.txt etc. tell AsciiDoc to produce pretty labels that refer to parts in an illustration, with <1>, <2>, etc.

Documentation/git-checkout.txt leave out at most one of `A` and `B`, in which case it defaults to `HEAD`. · line 297

Quoted 1 line
Documentation/git-checkout.txt +1 -0
+If we have moved away from commit f, then we must first recover its id

s/id/object name/;

Other than these three points, the description from "It is important" up to this point looks good.

Documentation/git-checkout.txt leave out at most one of `A` and `B`, in which case it defaults to `HEAD`. · line 304

Quoted 7 lines
Documentation/git-checkout.txt +7 -0
+(typically by using git reflog), and then we can create a reference to
+it. For example, to see the last two commits to which HEAD referred, we
+can use:
+
+------------
+$ git log -g -2 HEAD
+------------

A documentation written for people who do not know how to extract commit object names out of reflog, it is insufficient to give the command line example without giving a few lines of example output. Instead of "log -g", it probably is easier to use "git reflog -2" for this purpose.

Thanks.

#2 lore raw
Quoted 19 lines · Junio C Hamano

Documentation/git-checkout.txt leave out at most one of `A` and `B`, in which case it defaults to `HEAD`. · line 231

Quoted 4 lines · Jay Soffian
Documentation/git-checkout.txt +4 -0
+It is sometimes useful to be able to checkout a commit that is not at
+the tip of any named branch, or even to create a new commit that is not
+referenced by a named branch. Let's look at what happens when we
+checkout commit b:

I think it is a regression from the original text to omit mention of tags and replace the first example of the section with a more advanced use case of jumping to the middle of a branch; it is far more likely that a user would want to detach at a specific release point.

You can rectify it by tagging 'c' as a release point and detaching the HEAD at that tag without losing the clarity of the following description. While doing so, it would be better to update the labels in the illustration with s/master/master branch/ and s/[abcde]/commit &/ as well, e.g.

Quoted 7 lines

HEAD (refers to branch 'master')
|
V
a---b---c---d branch 'master' (refers to commit 'd')

          ^
          |
     tag 'v2.0' (refers to commit 'c')

While I agree with the above, I think this is still a good idea to keep this example using a non-tagged commit as well. Perhaps not the first one as you say.

Nicolas

#3 lore raw
Quoted 17 lines · Nicolas Pitre

On Thu, 17 Feb 2011, Junio C Hamano wrote:
...

Quoted 7 lines

You can rectify it by tagging 'c' as a release point and detaching the HEAD at that tag without losing the clarity of the following description. While doing so, it would be better to update the labels in the illustration with s/master/master branch/ and s/[abcde]/commit &/ as well, e.g.

Quoted 7 lines

HEAD (refers to branch 'master')
|
V
a---b---c---d branch 'master' (refers to commit 'd')

          ^
          |
     tag 'v2.0' (refers to commit 'c')
Quoted 3 lines

While I agree with the above, I think this is still a good idea to keep this example using a non-tagged commit as well. Perhaps not the first one as you say.

Just to make sure, I wasn't opposed to the idea of showing the history after building a few commits on top of the point you started from, to explain why you might want to re-attach the about-to-be-orphaned commits to the DAG anchored by refs.

IOW, detach at v2.0 tag, experiment with a few commits to fix things up, and then when things go well, make it a maitenance branch, or something.

#7 lore raw
In reply to Jay Soffian
Quoted 4 lines · Jay Soffian

The detached HEAD state is a source of much confusion for users new to git. Here we try to document it better.

Reworked from http://article.gmane.org/gmane.comp.version-control.git/138440

The patch may be difficult to read, so here's the man output after applying the patch:

DETACHED HEAD
HEAD normally refers to a named branch (e.g. "master"). Meanwhile, each branch refers to a specific commit-id. Let's look at a repo with three commits and with "master" checked out:

HEAD (refers to master)
v
a---b---c master (refers to c)

When a commit is created in this state, the branch is updated to the new commit-id. Let's add a commit:

HEAD (refers to master)
v
a---b---c---d master (refers to d)

It is sometimes useful to be able to checkout a commit that is not at the tip of any named branch, or even to create a new commit that is not referenced by a named branch. Let's look at what happens when we checkout commit b:

$ git checkout master^^

HEAD (refers to b)
v
a---b---c---d master (refers to d)

Notice that HEAD now refers directly to commit b. In git terminology, this is known as having a detached HEAD. It means simply that HEAD refers to a specific commit-id, as opposed to referring to a named branch. Let's add a commit while HEAD is detached:

HEAD (refers to e)
v
e
/
a---b---c---d master (refers to d)

We have created a new commit, but it is referenced only by HEAD. We can of course add yet another commit in this state:

HEAD (refers to f)
v
e---f
/
a---b---c---d master (refers to d)

In fact, we can perform all the normal git operations. But, let's look at what happens when we then checkout master:

$ git checkout master

e---f HEAD (refers to master)
/ v
a---b---c---d master (refers to d)

It is important to realize that at this point nothing refers to commits e and f. Eventually these commits will be deleted by the routine git garbage collection process, unless we create a reference before that happens. If we have not yet moved away from commit f, any of these will create a reference to it:

$ git checkout -b foo # (1)
$ git branch foo # (2)
$ git tag foo # (3)

(1) creates a new branch "foo", which refers to f, and then updates HEAD to refer to "foo". In other words, we'll no longer be in detached HEAD state after (1).

(2) similarly creates a new branch "foo", which refers to f, but leaves HEAD detached.

(3) creates a new tag "foo", which refers to f, leaving HEAD detached.

If we have moved away from commit f, then we must first recover its id (typically by using git reflog), and then we can create a reference to it. For example, to see the last two commits to which HEAD referred, we can use:

$ git log -g -2 HEAD

Acked-by on v1 1/1
#8 lore raw
In reply to Jay Soffian
Quoted 4 lines · Jay Soffian

The detached HEAD state is a source of much confusion for users new to git. Here we try to document it better.

Reworked from http://article.gmane.org/gmane.comp.version-control.git/138440

Excellent!

Quoted 2 lines
Quoted 3 lines

---
Nicolas only asked me to contribute this a full year ago, not too bad. :)

Better late than never.

Quoted 136 lines
 Documentation/git-checkout.txt |  108 +++++++++++++++++++++++++++++++---------
 1 files changed, 85 insertions(+), 23 deletions(-)
Documentation/git-checkout.txt +85 -23
index 880763d..21abd2a 100644
@@ -206,40 +206,102 @@ leave out at most one of `A` and `B`, in which case it defaults to `HEAD`.
 
 Detached HEAD
 -------------
+HEAD normally refers to a named branch (e.g. "master"). Meanwhile, each
+branch refers to a specific commit-id. Let's look at a repo with three
+commits and with "master" checked out:
 
-It is sometimes useful to be able to 'checkout' a commit that is
-not at the tip of one of your branches.  The most obvious
-example is to check out the commit at a tagged official release
-point, like this:
+------------
+           HEAD (refers to master)
+            v
+a---b---c  master (refers to c)
+------------
+
+When a commit is created in this state, the branch is updated to the new
+commit-id. Let's add a commit:
 
 ------------
-$ git checkout v2.6.18
+               HEAD (refers to master)
+                v
+a---b---c---d  master (refers to d)
 ------------
 
-Earlier versions of git did not allow this and asked you to
-create a temporary branch using the `-b` option, but starting from
-version 1.5.0, the above command 'detaches' your HEAD from the
-current branch and directly points at the commit named by the tag
-(`v2.6.18` in the example above).
+It is sometimes useful to be able to checkout a commit that is not at
+the tip of any named branch, or even to create a new commit that is not
+referenced by a named branch. Let's look at what happens when we
+checkout commit b:
 
-You can use all git commands while in this state.  You can use
-`git reset --hard $othercommit` to further move around, for
-example.  You can make changes and create a new commit on top of
-a detached HEAD.  You can even create a merge by using `git
-merge $othercommit`.
+------------
+$ git checkout master^^
 
-The state you are in while your HEAD is detached is not recorded
-by any branch (which is natural --- you are not on any branch).
-What this means is that you can discard your temporary commits
-and merges by switching back to an existing branch (e.g. `git
-checkout master`), and a later `git prune` or `git gc` would
-garbage-collect them.  If you did this by mistake, you can ask
-the reflog for HEAD where you were, e.g.
+   HEAD (refers to b)
+    v
+a---b---c---d  master (refers to d)
+------------
+
+Notice that HEAD now refers directly to commit b. In git terminology,
+this is known as having a detached HEAD. It means simply that HEAD
+refers to a specific commit-id, as opposed to referring to a named
+branch. Let's add a commit while HEAD is detached:
 
 ------------
-$ git log -g -2 HEAD
+     HEAD (refers to e)
+      v
+      e
+     /
+a---b---c---d  master (refers to d)
+------------
+
+We have created a new commit, but it is referenced only by HEAD. We can
+of course add yet another commit in this state:
+
+------------
+         HEAD (refers to f)
+          v
+      e---f
+     /
+a---b---c---d  master (refers to d)
+------------
+
+In fact, we can perform all the normal git operations. But, let's look
+at what happens when we then checkout master:
+
 ------------
+$ git checkout master
 
+      e---f    HEAD (refers to master)
+     /          v
+a---b---c---d  master (refers to d)
+------------
+
+It is important to realize that at this point nothing refers to commits
+e and f. Eventually these commits will be deleted by the routine git
+garbage collection process, unless we create a reference before that
+happens. If we have not yet moved away from commit f, any of these will
+create a reference to it:
+
+------------
+$ git checkout -b foo # (1)
+$ git branch foo      # (2)
+$ git tag foo         # (3)
+------------
+
+(1) creates a new branch "foo", which refers to f, and then updates HEAD
+to refer to "foo". In other words, we'll no longer be in detached HEAD
+state after (1).
+
+(2) similarly creates a new branch "foo", which refers to f, but leaves
+HEAD detached.
+
+(3) creates a new tag "foo", which refers to f, leaving HEAD detached.
+
+If we have moved away from commit f, then we must first recover its id
+(typically by using git reflog), and then we can create a reference to
+it. For example, to see the last two commits to which HEAD referred, we
+can use:
+
+------------
+$ git log -g -2 HEAD
+------------
 
 EXAMPLES
 --------
Signature · 1 line
1.7.4.1.29.g21713
#4 lore raw

PATCH 1/1 git-checkout.txt: improve detached HEAD documentation

In reply to Junio C Hamano

The detached HEAD state is a source of much confusion for users new to git. Here we try to document it better.

Reworked from http://article.gmane.org/gmane.comp.version-control.git/138440

---
Incorporated Junio's feedback. Though this is a bit clearer, I think it's starting to make the man page quite long due to the taller ascii art (adding the tag plus the stem to the arrows adds 4 lines to each picture).

I don't have any more time to allocate to this patch. I think it's a vast improvement as is, and you should feel free to make any corrections/edits you see fit so that it may be applied.

 Documentation/git-checkout.txt |  145 +++++++++++++++++++++++++++++++++------
 1 files changed, 122 insertions(+), 23 deletions(-)
Documentation/git-checkout.txt +122 -23
index 880763d..8a252dc 100644
@@ -206,40 +206,139 @@ leave out at most one of `A` and `B`, in which case it defaults to `HEAD`.
 
 Detached HEAD
 -------------
+HEAD normally refers to a named branch (e.g. 'master'). Meanwhile, each
+branch refers to a specific commit. Let's look at a repo with three
+commits, one of them tagged, and with branch 'master' checked out:
 
-It is sometimes useful to be able to 'checkout' a commit that is
-not at the tip of one of your branches.  The most obvious
-example is to check out the commit at a tagged official release
-point, like this:
+------------
+           HEAD (refers to branch 'master')
+            |
+            v
+a---b---c  branch 'master' (refers to commit 'c')
+    ^
+    |
+  tag 'v2.0' (refers to commit 'b')
+------------
+
+When a commit is created in this state, the branch is updated to refer to
+the new commit. Specifically, 'git commit' creates a new commit 'd', whose
+parent is commit 'c', and then updates branch 'master' to refer to new
+commit 'd'. HEAD still refers to branch 'master' and so indirectly now refers
+to commit 'd':
 
 ------------
-$ git checkout v2.6.18
+$ edit; git add; git commit
+
+               HEAD (refers to branch 'master')
+                |
+                v
+a---b---c---d  branch 'master' (refers to commit 'd')
+    ^
+    |
+  tag 'v2.0' (refers to commit 'b')
 ------------
 
-Earlier versions of git did not allow this and asked you to
-create a temporary branch using the `-b` option, but starting from
-version 1.5.0, the above command 'detaches' your HEAD from the
-current branch and directly points at the commit named by the tag
-(`v2.6.18` in the example above).
+It is sometimes useful to be able to checkout a commit that is not at
+the tip of any named branch, or even to create a new commit that is not
+referenced by a named branch. Let's look at what happens when we
+checkout commit 'b' (here we show three ways this may be done):
 
-You can use all git commands while in this state.  You can use
-`git reset --hard $othercommit` to further move around, for
-example.  You can make changes and create a new commit on top of
-a detached HEAD.  You can even create a merge by using `git
-merge $othercommit`.
+------------
+$ git checkout v2.0  # or
+$ git checkout b     # or
+$ git checkout master^^
+
+   HEAD (refers to commit 'b')
+    |
+    v
+a---b---c---d  branch 'master' (refers to commit 'd')
+    ^
+    |
+  tag 'v2.0' (refers to commit 'b')
+------------
 
-The state you are in while your HEAD is detached is not recorded
-by any branch (which is natural --- you are not on any branch).
-What this means is that you can discard your temporary commits
-and merges by switching back to an existing branch (e.g. `git
-checkout master`), and a later `git prune` or `git gc` would
-garbage-collect them.  If you did this by mistake, you can ask
-the reflog for HEAD where you were, e.g.
+Notice that regardless of which checkout command we use, HEAD now refers
+directly to commit 'b'. This is known as being in detached HEAD state.
+It means simply that HEAD refers to a specific commit, as opposed to
+referring to a named branch. Let's see what happens when we create a commit:
 
 ------------
-$ git log -g -2 HEAD
+$ edit; git add; git commit
+
+     HEAD (refers to commit 'e')
+      |
+      v
+      e
+     /
+a---b---c---d  branch 'master' (refers to commit 'd')
+    ^
+    |
+  tag 'v2.0' (refers to commit 'b')
 ------------
 
+There is now a new commit 'e', but it is referenced only by HEAD. We can
+of course add yet another commit in this state:
+
+------------
+$ edit; git add; git commit
+
+         HEAD (refers to commit 'f')
+          |
+          v
+      e---f
+     /
+a---b---c---d  branch 'master' (refers to commit 'd')
+    ^
+    |
+  tag 'v2.0' (refers to commit 'b')
+------------
+
+In fact, we can perform all the normal git operations. But, let's look
+at what happens when we then checkout master:
+
+------------
+$ git checkout master
+
+               HEAD (refers to branch 'master')
+      e---f     |
+     /          v
+a---b---c---d  branch 'master' (refers to commit 'd')
+    ^
+    |
+  tag 'v2.0' (refers to commit 'b')
+------------
+
+It is important to realize that at this point nothing refers to commit
+'f'. Eventually commit 'f' (and by extension commit 'e') will be deleted
+by the routine git garbage collection process, unless we create a reference
+before that happens. If we have not yet moved away from commit 'f',
+any of these will create a reference to it:
+
+------------
+$ git checkout -b foo   <1>
+$ git branch foo        <2>
+$ git tag foo           <3>
+------------
+
+<1> creates a new branch 'foo', which refers to commit 'f', and then
+updates HEAD to refer to branch 'foo'. In other words, we'll no longer
+be in detached HEAD state after this command.
+
+<2> similarly creates a new branch 'foo', which refers to commit 'f',
+but leaves HEAD detached.
+
+<3> creates a new tag 'foo', which refers to commit 'f',
+leaving HEAD detached.
+
+If we have moved away from commit 'f', then we must first recover its object
+name (typically by using git reflog), and then we can create a reference to
+it. For example, to see the last two commits to which HEAD referred, we
+can use either of these commands:
+
+------------
+$ git reflog -2 HEAD # or
+$ git log -g -2 HEAD
+------------
 
 EXAMPLES
 --------
Signature · 1 line
1.7.4.1.52.g8e1b
#5 lore raw

Documentation/git-checkout.txt leave out at most one of `A` and `B`, in which case it defaults to `HEAD`. · line 249

Quoted 9 lines · Jay Soffian
Documentation/git-checkout.txt +8 -0
+It is sometimes useful to be able to checkout a commit that is not at
+the tip of any named branch, or even to create a new commit that is not
+referenced by a named branch. Let's look at what happens when we
+checkout commit 'b' (here we show three ways this may be done):
 
+------------
+$ git checkout v2.0  # or
+$ git checkout b     # or
+$ git checkout master^^

I'd drop the second one, as "b" is not something the end user would type from the command line (you could say "b's commit ID" but the string 'b' is not it, unless it is a tag or something, in which case the first one that uses 'v2.0' already illustrates it), and adjust "three" accordingly.

Other than that, I think this version is a vast improvement over what we have.

Thanks.

#6 lore raw
Quoted 7 lines · Junio C Hamano
Quoted 5 lines · Jay Soffian
Documentation/git-checkout.txt +4 -0
+It is sometimes useful to be able to checkout a commit that is not at
+the tip of any named branch, or even to create a new commit that is not
+referenced by a named branch. Let's look at what happens when we
+checkout commit 'b' (here we show three ways this may be done):
Quoted 9 lines
Quoted 4 lines

+------------
+$ git checkout v2.0  # or
+$ git checkout b     # or
+$ git checkout master^^

I'd drop the second one, as "b" is not something the end user would type from the command line (you could say "b's commit ID" but the string 'b' is not it, unless it is a tag or something, in which case the first one that uses 'v2.0' already illustrates it)

Ah, in my mind, b _is_ the commit-ID. In your mind, b is the commit. Fair enough, drop it.

Quoted 2 lines

and adjust "three" accordingly. Other than that, I think this version is a vast improvement over what we have.

Would you mind amending what you've got so I don't have to resend?

Thanks,

j.