LoginSignup
0
0

More than 1 year has passed since last update.

git で push 前の古い(最新じゃない)コミットメッセージを変更する方法

Last updated at Posted at 2021-10-12

背景

  • 古いコミットメッセージにプロジェクト名を追記したい。

手順

修正したいコミットまでの数を確認

$ git log

# コミット番号は省略
    [nest-retrospective] first commit  # ← 最新のコミット(1番目)

    DailyReview機能、WeeklyReview機能作成 # ← 修正したいコミット

    first commit
  • 一番新しいコミットを1とする。
  • git rebase -i HEAD~nnには、修正したいコミットまでの数字が入る。
  • 今回、最新のコミットから数えて2番目のコミットを変更したいのでn2となる。
$ git rebase -i HEAD~2

# 最新のコミットから2つまでのコミットが表示される
pick 2520311 DailyReview機能、WeeklyReview機能作成
pick 228e7f4 [nest-retrospective] first commit
  • vimエディタが開くので、iを押して入力モードに切り替える。
    • エディタの下側に --INSERT--が表示される。

修正したいコミット先頭のpickeditに書き換える。

edit 2520311 DailyReview機能、WeeklyReview機能作成
pick 228e7f4 [nest-retrospective] first commit
  • esc(コマンドモードに切り替わる)→:wq(ファイルを上書き保存しvimエディタを終了)→Enter

コミットメッセージを修正

$ git commit --amend -m "[nest-test] DailyReview機能、WeeklyReview機能作成"

rebase処理を再開

$ git rebase --continue
Successfully rebased and updated refs/heads/main.

コミットメッセージを変更できたか確認

$ git log

Date:   Tue Oct 12 12:13:53 2021 +0900

    [nest-retrospective] first commit


Date:   Mon Oct 11 17:06:23 2021 +0900

    [nest-test] DailyReview機能、WeeklyReview機能作成 # ← 無事変更されてる


Date:   Sun Sep 26 18:49:07 2021 +0900

    first commit

参考サイト

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