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 commit メッセージに日付を自動付与する方法(zsh関数で効率アップ)

0
Last updated at Posted at 2025-07-21
  • Gitでコミットメッセージを記述するとき、「いつコミットしたか」を毎回メモしてませんか?
  • コミット末尾に _2025_0721_10-00 のような日時を 自動で付けられる方法 があったので共有いたします!

📌 使用ツール

  • Git
  • zsh(またはbash)
  • エイリアス(alias)機能

📌 今回行うこと

ターミナルでgit commit -m "変更内容"を入力する時に
自動で末尾に2025_0721_10-00のようにコミット日付を入れる。


📌 導入手順

① ターミナルで .zshrc を開く

使用しているシェルに応じて、以下のいずれかを開きます:

code ~/.bashrc

② 以下の関数を追記する

# 自動コミット関数:引数メッセージ + _YYYYMMDD_HH-MM
gitac () {
  git add .
  git commit -m "${1}_$(date +%Y%m%d_%H-%M)"
}

③ 設定を反映させる

source ~/.zshrc

③ ターミナルでgitac "変更点"と入力

gitac "ログイン画面作成"

と入力することで、
自動で、下記が実行されます!

git add .
git commit -m "ログイン画面作成_20250721_10-00

📌 注意

gitac 関数は ターミナルで実行したときのみ 有効です。

VS Code の GUI(ソース管理パネル)から add や commit をしても、この関数は使われません。
必ず ターミナルで gitac を実行してください!


📌 まとめ

毎回日付をつける手間が省けて、履歴もすっきり。
個人開発や学習ログにもおすすめです💡

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?