肉とビールとパンケーキ by @sotarok

少し大人になった「肉とご飯と甘いもの」

Git で過去にさかのぼってタグ付けする (git tag)

もうだいぶ歴史を進めて開発進めてたんだけど、そういやあのプロトタイプが動いたときタグうっときゃよかったなーなどと思ったんだけど、意外と情報がなかったからメモ。
git-flow 使って、develop で開発進めてたりして、リモート/ローカルで push/pull も頻繁にしてるリポジトリ。現存するのは、develop, master のみ、だいぶ昔に feature/hoge からマージした段階に戻って master にマージしてタグ付けしたい、みたいな要望(割とあるよね?あるよね?

$ git log --all --graph

とか見ながら、コミットオブジェクトのハッシュ確認。例えば、「38fef39」が対象のコミットだとする。

そのハッシュをチェックアウト。

$ git checkout 38fef39
Note: checking out '38fef39'.

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 38fef39... hogehoge

この時点では、どのブランチにも属していない状態になる。なので、一旦ブランチ切ってそこに入る。releaseブランチを切ってしまおう。

$ git branch -a
* (no branch)
  develop
  master
  remotes/origin/develop
  remotes/origin/master

$ git checkout -b release/0.0.1

masterをチェックアウトして、merge。no fast forward で。

$ git checkout master
$ git merge --no-ff release/0.0.1

で、タグを打つ。

$ git tag -a 0.0.1

あとはブランチ削除

$ git branch -d release/0.0.1

完了!