1
1

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 tagでsortとformatを使いこなそう

Posted at

git tagのデフォルトだと、情報量が少なくてあんまりよくわからんこと多いので使い方調べたメモ

基本

めんどくさくてwebで調べがちだけど、manを一度読むべき.

$ man git-tag
NAME
       git-tag - Create, list, delete or verify a tag object signed with GPG

SYNOPSIS
       git tag [-a | -s | -u <keyid>] [-f] [-m <msg> | -F <file>] [-e]
               <tagname> [<commit> | <object>]
       git tag -d <tagname>...
       git tag [-n[<num>]] -l [--contains <commit>] [--no-contains <commit>]
               [--points-at <object>] [--column[=<options>] | --no-column]
               [--create-reflog] [--sort=<key>] [--format=<format>]
               [--merged <commit>] [--no-merged <commit>] [<pattern>...]
       git tag -v [--format=<format>] <tagname>...

タグ付けする使い方

git tag [-a | -s | -u <keyid>] [-f] [-m <msg> | -F <file>] [-e] <tagname> [<commit> | <object>]

タグを削除する使い方

git tag -d <tagname>...

タグをリストアップする使い方

git tag [-n[<num>]] -l [--contains <commit>] [--no-contains <commit>] ...

タグのGPG signatureをverifyする使い方

git tag -v [--format=<format>] <tagname>...

タグのリストアップ

デフォルトだとタグのみ

$ git tag -l
0.0.5
0.0.7
v0.0.1
v0.0.2
v0.0.3
v0.0.4
v0.0.5
v0.0.6
v0.0.7
v1.0.0
v1.1.0
v1.1.1
v1.1.2
v1.1.3
v1.2.0
v1.2.1
v1.3.0

format

--format でフォーマット指定. デフォルトは %(refname:strip=2).

$ git tag -n -l --format='%(refname:strip=2)'
0.0.5
0.0.7
v0.0.1
v0.0.2
v0.0.3
v0.0.4
v0.0.5
v0.0.6
v0.0.7
v1.0.0
v1.1.0
v1.1.1
v1.1.2
v1.1.3
v1.2.0
v1.2.1
v1.3.0

使えるkeyの一覧はmanにはのってなかった. 直接sourceをみるとこれっぽい.

よく使いそう

  • refname: tagの名前とか
  • authorname: 作った人
  • authordate: 作った日付
  • subject: コミットメッセージ
$ git tag -n -l --format='%(refname:strip=2) %(authordate:short) %(authorname) %(subject)'
0.0.5 2019-05-15 Juan Leni fixing linter issues
0.0.7 2020-03-27 Joshua Harshman Partial Revert of #922 (#1068)
v0.0.1 2017-10-12 Thomas Cyron Create new buffer if not present yet (#549)
v0.0.2 2018-03-21 Michael Update the Travis and CircleCI Go versions (#651)
v0.0.3 2018-04-27 Zef Hemel Fixed code sample for bash completion (#687)
v0.0.4 2019-03-21 Willi Eggeling added variable to allow configuration of mousetrap message duration (#809)
v0.0.5 2019-05-15 Juan Leni fixing linter issues
v0.0.6 2020-02-20 Alexandr Burdiyan Add support for context.Context
v0.0.7 2020-03-27 Joshua Harshman Partial Revert of #922 (#1068)
v1.0.0 2020-04-10 Marc Khouzam Fish completion using Go completion (#1048)
v1.1.0 2020-10-14 Adam Demuri Add example for making persistent flags required (#1135)
v1.1.1 2020-10-18 Sascha Steinbiss fix manpage building with new go-md2man (#1255)
v1.1.2 2021-02-09 Anthony Fok Update CHANGELOG.md for v1.1.2
v1.1.3 2021-02-10 Anthony Fok Fix typo
v1.2.0 2021-07-01 Marc Khouzam Fix documentation (#1434)
v1.2.1 2021-07-02 Paul Holzinger Fix flag completion (#1438)
v1.3.0 2021-12-14 dependabot[bot] Bump github.com/spf13/viper from 1.9.0 to 1.10.0 (#1561)

authordateなんかのフォーマットはここらへんっっぽい

formatが何でも自由にできて便利

$ git tag -n -l --format='%(refname:strip=2) %(authordate:format:%Y-%m-%d_%H:%M:%S)'
0.0.5 2019-05-15_18:53:39
0.0.7 2020-03-27_14:38:32
v0.0.1 2017-10-12_20:25:33
v0.0.2 2018-03-21_14:39:34
v0.0.3 2018-04-27_15:45:50
v0.0.4 2019-03-21_01:05:52
v0.0.5 2019-05-15_18:53:39
v0.0.6 2020-02-20_07:29:50
v0.0.7 2020-03-27_14:38:32
v1.0.0 2020-04-10_15:56:28
v1.1.0 2020-10-14_09:53:09
v1.1.1 2020-10-18_20:59:26
v1.1.2 2021-02-09_18:39:00
v1.1.3 2021-02-10_12:40:59
v1.2.0 2021-07-01_11:49:30
v1.2.1 2021-07-02_17:25:47
v1.3.0 2021-12-14_11:22:51

sort

表示したらsortもついでにやりたいのが人の常.

--sort でkeyを指定してソートできる.

$ git tag -l --sort refname | head
0.0.5
0.0.7
v0.0.1
v0.0.2
v0.0.3
v0.0.4
v0.0.5
v0.0.6
v0.0.7
v1.0.0

keyのまえに-をつけることでreverse sortできる.

$ git tag -l --sort -refname | head
v1.3.0
v1.2.1
v1.2.0
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.0
v0.0.7
v0.0.6

key listはformat同様に使えるっぽい

authordateとか使うと最新順で並びそう

$ git tag -l --sort -authordate | head
v1.3.0
v1.2.1
v1.2.0
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.0
0.0.7
v0.0.7

おわり

git-tagでsortとformat使えると便利.
いろんなOSSのプロジェクトでgit-tag表示すると楽しい.
vつけるのミスってたり、夜中にコミットしてたりで人間味が感じられるよね.

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?