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/02-git-basics/sections/tagging.asc
+25-3
Original file line number
Diff line number
Diff line change
@@ -211,13 +211,35 @@ Now, when someone else clones or pulls from your repository, they will get all y
211
211
212
212
==== Checking out Tags
213
213
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:
216
238
217
239
[source,console]
218
240
----
219
241
$ git checkout -b version2 v2.0.0
220
242
Switched to a new branch 'version2'
221
243
----
222
244
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