Skip to content

Commit b187fa9

Browse files
authored
Merge pull request #786 from TheHeartmann/master
Correct section on checking out tags
2 parents 7c78ac3 + fc4ec46 commit b187fa9

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

book/02-git-basics/sections/tagging.asc

+25-3
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,35 @@ Now, when someone else clones or pulls from your repository, they will get all y
211211

212212
==== Checking out Tags
213213

214-
You can't really check out a tag in Git, since they can't be moved around.
215-
If you want to put a version of your repository in your working directory that looks like a specific tag, you can create a new branch at a specific tag with `git checkout -b [branchname] [tagname]`:
214+
If you want to view the versions of files a tag is pointing to, you can do a git checkout, though this puts your repository in ``detached HEAD'' state, which has some ill side effects:
215+
216+
[source,console]
217+
----
218+
$ git checkout 2.0.0
219+
Note: checking out '2.0.0'.
220+
221+
You are in 'detached HEAD' state. You can look around, make experimental
222+
changes and commit them, and you can discard any commits you make in this
223+
state without impacting any branches by performing another checkout.
224+
225+
If you want to create a new branch to retain commits you create, you may
226+
do so (now or later) by using -b with the checkout command again. Example:
227+
228+
git checkout -b <new-branch-name>
229+
230+
HEAD is now at 99ada87... Merge pull request #89 from schacon/appendix-final
231+
232+
$ git checkout 2.0-beta-0.1
233+
Previous HEAD position was 99ada87... Merge pull request #89 from schacon/appendix-final
234+
HEAD is now at df3f601... add atlas.json and cover image
235+
----
236+
237+
In ``detached HEAD'' state, if you make changes and then create a commit, the tag will stay the same, but your new commit won't belong to any branch and will be unreachable, except for by the exact commit hash. Thus, if you need to make changes—say you're fixing a bug on an older version, for instance—you will generally want to create a branch:
216238

217239
[source,console]
218240
----
219241
$ git checkout -b version2 v2.0.0
220242
Switched to a new branch 'version2'
221243
----
222244

223-
Of course if you do this and do a commit, your `version2` branch will be slightly different than your `v2.0.0` tag since it will move forward with your new changes, so do be careful.
245+
If you do this and make a commit, your `version2` branch will be slightly different than your `v2.0.0` tag since it will move forward with your new changes, so do be careful.

0 commit comments

Comments
 (0)