LoginSignup
0
0

More than 1 year has passed since last update.

【git】git tagの削除と^{ }付タグについて

Last updated at Posted at 2022-02-18

git tagを消したい➡︎同じタグ2つ有る➡︎片方^{}付いてる➡︎ナニコレどっち消せば良いの?

リリースに合わせてバージョンのタグを打ったけれど、その後、軽微な変更が必要な事が分かり、タグを消したいという事もあるかと思います

まさにそんな状況でタグを削除しようと思ったら、同じタグが2つ有り、混乱したのでメモ

tagの削除

タグの削除は以下の順序で行えます

ローカルのタグを削除

  1. git tagコマンドでタグ一覧を確認
  2. git tagコマンドに-dオプションを付けて、タグを指定し、削除
## ローカルのタグ一覧を確認
% git tag
android_1.0.0
android_1.0.1
android_1.1.0
android_1.1.1
android_1.1.2
android_1.10.0

## タグの削除
% git tag -d android_1.10.0
Deleted tag 'android_1.10.0' (was 752badb)

リモートのタグを削除

  1. git ls-remote --tagsでリモートのタグ一覧を確認
  2. git pushコマンドに--deleteオプションを付けて、タグを指定し、削除

--deleteオプションは:(コロン)で省略も可能

## リモートのタグ一覧を確認
% git ls-remote --tags
From git@github.com:hogehoge/sample_repository.git
24f380f0c7533b8935e93af57a8bd4502c4cdac9        refs/tags/android_1.0.0
24f380f0c7533b8935e93af57a8bd4502c4cdac9        refs/tags/android_1.0.1
24f380f0c7533b8935e93af57a8bd4502c4cdac9        refs/tags/android_1.1.0
24f380f0c7533b8935e93af57a8bd4502c4cdac9        refs/tags/android_1.1.1
24f380f0c7533b8935e93af57a8bd4502c4cdac9        refs/tags/android_1.1.2
752badb1ca34530cf1f0fc059b765dff0cb74bc9        refs/tags/android_1.10.0

## タグの削除
% git push origin --delete android_1.10.0
To https://github.com/hogehoge/sample_repository.git
 - [deleted]         android_1.10.0

% git push origin :android_1.10.0
To https://github.com/hogehoge/sample_repository.git
 - [deleted]         android_1.10.0

タグ一覧に同名のタグが2つ、片方に^{}付いてる

git ls-remote --tagsをした際に表題の通り、同名のタグが2つ、そして片方に^{}付いていました

さてどちらを消したら良いのか...:thinking:

% git ls-remote --tags
From git@github.com:hogehoge/sample_repository.git
24f380f0c7533b8935e93af57a8bd4502c4cdac9        refs/tags/android_1.0.0
24f380f0c7533b8935e93af57a8bd4502c4cdac9        refs/tags/android_1.0.1
24f380f0c7533b8935e93af57a8bd4502c4cdac9        refs/tags/android_1.1.0
24f380f0c7533b8935e93af57a8bd4502c4cdac9        refs/tags/android_1.1.1
24f380f0c7533b8935e93af57a8bd4502c4cdac9        refs/tags/android_1.1.2
752badb1ca34530cf1f0fc059b765dff0cb74bc9        refs/tags/android_1.2.0    # <-
df6db13cd08027e8680420d4818d42edd4c0db14        refs/tags/android_1.2.0^{} # <- 同じタグ番号が2つ

^{}付のタグは何か?

タグには2種類有るそうです
1. lightweight:単純にコミットに対する参照を保持した簡易版タグ
1. annotated:上記情報以外にもtagger(tag生成した人)など付帯した情報を保持したgitオブジェクト

タグ生成時に-aオプションでタグを生成すると上記のannotatedタグになります

^{}が付いたタグは上記で言うとlightweightタグになります

## lightweight
% git show df6db13cd08027e8680420d4818d42edd4c0db14 
commit df6db13cd08027e8680420d4818d42edd4c0db14 (tag: android_1.10.0)
Author: heyhey1028 <hogehoge@gmail.com>
Date:   Wed Jan 6 17:46:48 2021 +0900

    add: androidリリースバージョンを更新

diff --git a/sample/pubspec.yaml b/sample/pubspec.yaml
index 3076e7e12..b22b2ca66 100644
--- a/sample/pubspec.yaml
+++ b/sample/pubspec.yaml
@@ -2,7 +2,7 @@ name: sample
 description: A new Flutter project.

 publish_to: "none"
-version: 1.9.0+31
+version: 1.10.0+32

 environment:
   sdk: ">=2.10.0 <3.0.0"

## annotated
% git show 752badb1ca34530cf1f0fc059b765dff0cb74bc9   
tag android_1.10.0
Tagger: heyhey1028 <hogehoge@gmail.com>
Date:   Wed Jan 13 10:44:58 2021 +0900

Customer 1.10.0+32

commit df6db13cd08027e8680420d4818d42edd4c0db14 (tag: android_1.10.0)
Author: heyhey1028 <hogehoge@gmail.com>
Date:   Wed Jan 6 17:46:48 2021 +0900

    add: androidリリースバージョンを更新

diff --git a/sample/pubspec.yaml b/sample/pubspec.yaml
index 3076e7e12..b22b2ca66 100644
--- a/sample/pubspec.yaml
+++ b/sample/pubspec.yaml
@@ -2,7 +2,7 @@ name: sample
 description: A new Flutter project.

 publish_to: "none"
-version: 1.9.0+31
+version: 1.10.0+32

 environment:
   sdk: ">=2.10.0 <3.0.0"

どちらを消したら良いの?

結論から言えば、annotatedタグを削除すれば両方削除されます

annotatedタグはlightweightタグへの参照も保持しています。その為、lightweightタグがある場合、対応するannotatedタグが存在し、lightweightタグへの参照も保持しているannotatedタグを消す事で両方削除する事が出来ます

% git push origin --delete android_1.10.0
To https://github.com/hogehoge/sample_repository.git
 - [deleted]         android_1.10.0

以上でした!どなたかの参考になれば幸いです

参考

0
0
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
0
0