0
0

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 1 year has passed since last update.

【勉強用】Gitのコマンドを実際に動かしてみた(④タグ編)

0
Last updated at Posted at 2023-11-04

はじめに

今回はGitのコマンドを実際に動かして、バージョンの確認や変更について理解を深めたいと思います。参考図書はこちらの動かして学ぶ!Git入門を使用しました。

image.png

コマンド

28. git tag

このコマンドはコミットに対して軽量タグを付与する際に使用するコマンドです。具体的には以下の種類があります。

git tag:タグの一覧を確認する
git tag タグ名:HEADに指定のタグ名を付与する
git tag コミット名 タグ名指定のコミットに、指定のタグ名を付与する

それでは、mainブランチのHEADにv1.0というタグ名を付与してみましょう。

Git Bash
$ git show
commit b79fc143954f94225a3527c3e9fa72d31efa8496 (HEAD -> main, tag: v1.0) #タグ名が確認できる
Merge: 8ba08a1 1ca01f9
Author: HANAKO <hanako@sample.com>
Date:   Sat Nov 4 07:07:50 2023 +0900

    resolve conflict

diff --cc hello.txt
index e75d1e7,598d37b..3395ded
--- a/hello.txt
+++ b/hello.txt
@@@ -1,4 -1,4 +1,5 @@@
  hello!
  Hello, everyone!
  Have a nice day !
- Yeah !
 -Hoo !
++Yeah !
++

無事にタグ名を付与できましたね。

29. git tag -d タグ

このコマンドはタグを削除する際に使用するコマンドです。

それではhello.txtに新たにVery Nice !という文章を追加し、コミットを行います。そのコミットに対してv2.0というタグ名を付与します。そのタグを削除してみましょう。

Git Bash
#hello.txtにVery Nice!という文章を追加
$ git add hello.txt
$ git commit -m "commit Very Nice !"
[main 36c7012] commit Very Nice !
 1 file changed, 1 insertion(+)

$ git show
commit 36c7012f78f1b1f8fd038a2a313ee188ba7c5206 (HEAD -> main, tag: v2.0) #タグ名を確認
Author: HANAKO <hanako@sample.com>
Date:   Sat Nov 4 09:08:18 2023 +0900

    commit Very Nice !

diff --git a/hello.txt b/hello.txt
index 3395ded..2ed56f5 100644
--- a/hello.txt
+++ b/hello.txt
@@ -2,4 +2,5 @@ hello!
 Hello, everyone!
 Have a nice day !
 Yeah !
+Very Nice !

$ git tag -d v2.0
Deleted tag 'v2.0' (was 36c7012)

$ git show
commit 36c7012f78f1b1f8fd038a2a313ee188ba7c5206 (HEAD -> main) #タグが無くなっていることを確認
Author: HANAKO <hanako@sample.com>
Date:   Sat Nov 4 09:08:18 2023 +0900

    commit Very Nice !

diff --git a/hello.txt b/hello.txt
index 3395ded..2ed56f5 100644
--- a/hello.txt
+++ b/hello.txt
@@ -2,4 +2,5 @@ hello!
 Hello, everyone!
 Have a nice day !
 Yeah !
+Very Nice !

無事にタグを削除できました。

まとめ

今回の記事では、タグの操作を中心に学習しました。次回はリモートリポジトリの扱いについて学習したいと思います。

前回:【勉強用】Gitのコマンドを実際に動かしてみた(③ブランチ編)
次回:【勉強用】Gitのコマンドを実際に動かしてみた(⑤リモートリポジトリ編)

参考文献

動かして学ぶ!Git入門

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?