File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed
book/02-git-basics/sections Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change 230
230
231
231
==== 检出标签
232
232
233
- 在 Git 中你并不能真的检出一个标签,因为它们并不能像分支一样来回移动。
234
- 如果你想要工作目录与仓库中特定的标签版本完全一样,可以使用 `git checkout -b [branchname] [tagname]` 在特定的标签上创建一个新分支:
233
+ 如果你想查看某个标签所指向的文件版本,可以使用 `git checkout` 命令,虽然说这会使你的仓库处于“detacthed HEAD”状态——这个状态有些不好的副作用:
234
+
235
+ [source,console]
236
+ ----
237
+ $ git checkout 2.0.0
238
+ Note: checking out '2.0.0'.
239
+
240
+ You are in 'detached HEAD' state. You can look around, make experimental
241
+ changes and commit them, and you can discard any commits you make in this
242
+ state without impacting any branches by performing another checkout.
243
+
244
+ If you want to create a new branch to retain commits you create, you may
245
+ do so (now or later) by using -b with the checkout command again. Example:
246
+
247
+ git checkout -b <new-branch>
248
+
249
+ HEAD is now at 99ada87... Merge pull request #89 from schacon/appendix-final
250
+
251
+ $ git checkout 2.0-beta-0.1
252
+ Previous HEAD position was 99ada87... Merge pull request #89 from schacon/appendix-final
253
+ HEAD is now at df3f601... add atlas.json and cover image
254
+ ----
255
+
256
+ 在“detached HEAD”状态下,如果你做了些更改然后提交它们,标签不会发生变化,但你的新提交将不属于任何分支,并且将无法访问,除非确切的提交哈希。因此,如果您需要进行更改——比如说你正在修复旧版本的错误——你通常需要创建一个新分支:
235
257
236
258
[source,console]
237
259
----
238
260
$ git checkout -b version2 v2.0.0
239
261
Switched to a new branch 'version2'
240
262
----
241
263
242
- 当然,如果在这之后又进行了一次提交,`version2` 分支会因为改动向前移动了,那么 `version2` 分支就会和 `v2.0.0` 标签稍微有些不同,这时就应该当心了。
264
+ 当然,如果在这之后又进行了一次提交,`version2` 分支会因为这个改动向前移动了, `version2` 分支就会和 `v2.0.0` 标签稍微有些不同,这时就应该当心了。
You can’t perform that action at this time.
0 commit comments