git でタグを切る/チェックアウトする

修正を push。

$ git push git.sample.jp:path.to.repos

このタイミングでタグを切っておこうと思い立つ。
hash で指定してみる。

git log --pretty=oneline

目的の hash でタグ切る。今回は tags_ver_1.0.0 という名前で。

git tag tags_ver_1.0.0 123456789012345678901234567890abcdeabcd

レポジトリに反映。

git push origin tags_ver_1.0.0

タグを指定してチェックアウトしてみる。

$ git clone git.sample.jp:path.to.repos
$ git branch
* master

branch は master のみ。
タグ一覧を確認。

$ git tag -l
tags_ver_1.0.0

さっき切ったタグが表示される。こいつをチェックアウト。

$ git checkout tags_ver_1.0.0
Note: checking out 'tags_ver_1.0.0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at 123456... fix invalid permission description
$ git branch
* (no branch)
  master

何かプチ怒られしました。
branch を作成せずに tag を checkout すると、detached HEAD なる状態になるようです。
タグを切った状態のスナップショットが欲しいだけならばコレで全く問題ありませんが、ここを起点にさらにバリバリ開発を継続するのであれば、ブランチを作成してチェックアウトしたほうがよさそうです。

$ git checkout -b tags_ver_1.0.0