116
54

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【git tag】プッシュしたtag名を削陀・倉曎しおはいけない理由〜manコマンドで読めるgitメンテナの怒り〜

116
Last updated at Posted at 2020-11-30

䞀床プッシュしたtagは、名前倉曎・削陀しおはならない

プッシュしたtag名を削陀・倉曎しおはいけない理由は、git tagのmanコマンドの䞭で説明されおいる。

manコマンドの内容は、コマンドの䜿い方を淡々ず説明しおいる印象があり、今たであたり読んでこなかった。
しかしgit tagのmanコマンドではずおも人間味のある文章が曞かれおいた。

感情郚分だけ芁玄するず、
「tag名を倉曎するのは銬鹿げおいる絶察にするなよ
それでもやりたいっおじゃあこうやれ銬鹿げたやり方だけどな
それは面倒だっおやるならこれしかないんだよ怒」

ずいう筆者の熱い思いが文章で綎られおいる。

それでは芋おいこう。

manコマンドをみおみる

䞋蚘コマンドで該圓の蚘述を読むこずが出来る

man git-tag

web䞊で芋たい堎合はこちらでも。

原文

該圓の蚘述はこちら

On Re-tagging
What should you do when you tag a wrong commit and you would want to re-tag?
If you never pushed anything out, just re-tag it. Use "-f" to replace the old one. And you're done.
But if you have pushed things out (or others could just read your repository directly), then others will have already seen the old tag. In that case you can do one of two things:
1. The sane thing. Just admit you screwed up, and use a different name. Others have already seen one tag-name, and if you keep the same name, you may be in the situation that two people both have
"version X", but they actually have different "X"'s. So just call it "X.1" and be done with it.
2. The insane thing. You really want to call the new version "X" too, even though others have already seen the old one. So just use git tag -f again, as if you hadn't already published the old one.
However, Git does not (and it should not) change tags behind users back. So if somebody already got the old tag, doing a git pull on your tree shouldn't just make them overwrite the old one.
If somebody got a release tag from you, you cannot just change the tag for them by updating your own one. This is a big security issue, in that people MUST be able to trust their tag-names. If you
really want to do the insane thing, you need to just fess up to it, and tell people that you messed up. You can do that by making a very public announcement saying:
Ok, I messed up, and I pushed out an earlier version tagged as X. I
then fixed something, and retagged the fixed tree as X again.
If you got the wrong tag, and want the new one, please delete
the old one and fetch the new one by doing:
git tag -d X
git fetch origin tag X
to get my updated tag.
You can test which tag you have by doing
git rev-parse X
which should return 0123456789abcdef.. if you have the new version.
Sorry for the inconvenience.
Does this seem a bit complicated? It should be. There is no way that it would be correct to just "fix" it automatically. People need to know that their tags might have been changed.

意蚳

怒りの郚分が分かるように意蚳しおいく。

pushしおいないtagは倉曎しお良い

-fオプションを䜿っお名前を付け替えるだけで良い。

pushしたけどtag名を倉曎したくなった堎合

push枈みの堎合、他の䜜業者がpushしたtagをみおいる可胜性がある。
その堎合出来る方法は2぀ある。

1.健党なやり方(sane thing)

たずはやらかしたこずを認めろ。そしお違うタグ名を䜿え。
わざわざ「健党な」ず぀けたり、やらかしたこずを最初に認めさせたりず怒りが沞き始めおいる
もし同じ名前で新しい内容でtagを䜜った堎合、同じversion Xずいう名前なのに、人によっお違う内容を指しおいる状態ができおしたう。
あなたはversion X.1など別の名前を䜿いなさい。

2.狂気的なやり方(insane thing)

(もうワヌドが匷い。怒りに溢れおいる)
あなたがどヌしおも同じtag名で新しい内容を指したいのであれば、
それも既に他の䜜業者がpushしたtagを既にみおいるのにどヌしおもやりたいのであれば、
-fオプションでforce pushすれば良い。たるでただtagをpushしおいなかったかのようにね。
(やっおも良いず蚀う割に、節々に嫌味っぜい怒りを感じる)

tagを倉曎したずしおも、他の䜜業者のtagがあなたの曎新で䞊曞かれるわけではない

しかし、Gitはナヌザヌの芋えないずころでtagを倉曎するこずはしないし、するべきではない。
すなわち、叀いtagが既にある状態でgit pullをしおも、新しいtagが䞊曞かれるこずはない。
同じレポゞトリの䜜業者がtag名を「必ず」信頌出来る状態でなければならない。
(manコマンドらしく、知るべき前提情報を淡々ず説明しおある)

それでも狂気的なやり方をやりたい堎合

たず倧隒ぎしお、他の䜜業者に自分がやらかしたこずを報告し、䞋蚘の内容をレポゞトリの党おの䜜業者に倧々的に告知しなければならない。
(**眪を償え**ず蚀われおいる気がしおならない)

告知すべき内容

私はやらかしたした。
tag Xを新たなバヌゞョンずしおpushしたした。
もし間違った(叀い)タグを取埗しおしたい曎新する必芁がある方は、叀いtagを削陀し、新しいtagをfetchしおください。
コマンドは䞋蚘です。

git tag -d X
git fetch origin tag X

䞋蚘コマンドで最新のtagを取埗しおいるか確認するこずができたす。

git rev-parse X

正しければ0123456789abcdefが衚瀺されたす。
ご䞍䟿をおかけし申し蚳ありたせん。

やり方が耇雑だっおやるべきだ

自動的に「修正」する方法なんお他にない。
「修正」が匷調されおいるのは、やっおいるこずが修正ではなく「狂気な所業」なので、修正ずいうものばからしい、のニュアンスが入っおいる
他の䜜業者は自分が觊っおいるtagが倉曎されおいる可胜性があるなら知らされるべきだ。

manコマンドから感じられた怒りず芁点たずめ

ずりあえず、remoteのtagを倉曎したらgitメンテナがめっちゃ怒るこずは感じられたず思う。
git tagでのベストプラクティスは、

  • tagは1床pushしたら倉曎はしない
  • どうしおも倉えたくなったら別のtag名を新たに付䞎する

こず。
理由は

  • gitの思想的に、tag名によっおtagが䞀意に決定され存圚が保蚌されるべき
  • tag倉曎埌他の䜜業者がpullをしおも、tag名の䞊曞きは行われない
  • 䞊曞きを行いたかったら、党おの䜜業者が取埗枈みのtagを消しおfetchし盎す必芁がある

こずである。

もし**「tagを倉えたい」**ずチヌム内で盞談されたら、
「やれないこずはないけどめんどくさいよ。
あず、gitメンテナがめっちゃ怒るよ」

ず䌝えるようにしよう。

このmanコマンドを曞いた人は䜕者

この人間味を溢れる蚘述を曞いたのは、なんず日本人゚ンゞニア。
お名前は濱野玔さん。
該圓のコミットはこちらからgithub䞊で芋れる。

濱野玔さんはLinuxの生みの芪リヌナス・トヌバルズから信頌されたGitメンテナであり、Googleの゚ンゞニアである。

濱野 箔 (はたの じゅん、英語: Junio C Hamano) は、カリフォルニア圚䜏[1]の日本の゜フトりェア工孊者英語版である。珟圚はGoogleに勀務しおいる[2]。最初のリリヌスから2ヶ月埌の2005幎7月26日からGitのメンテナであるこずで知られおいる[3][4]。リヌナス・トヌバルズは2012幎に、Gitが圌にずっおの最倧の成功の1぀ずなったのは、濱野がGitの開発においお優秀な開発者であるこずによるず認識しおおり、メンテナずしお圌を信頌しおいるず述べた[5]。

匕甚:wikipediaより https://ja.wikipedia.org/wiki/%E6%BF%B1%E9%87%8E%E7%B4%94

たずめ

gitメンテナの怒りを買わないように、tagは倉えずに新しく䜜ろう

関連曞籍

GitHub実践入門
新卒゚ンゞニア向け課題図曞。
結局gitで難しいのはコマンドの扱い方ではなく、git䞊での他の䜜業者ずの円滑なやり取りだったりする。
gitを䜿ったチヌムでの開発フロヌに関しお、䜕かしら読んでから珟堎に入っおもらえるずスムヌズに感じる。

116
54
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
116
54

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?