概要
Githubでコミット名を後から変更する方法を紹介します。
「GitHub コミット名 変更」で検索するとrebaseしてeditする方法が出てきますが、それよりも簡単な方法です。
注意
この記事は新卒エンジニアが執筆しています。
そのため内容に間違いや不備がある場合があります。
もし間違いを発見しましたら、どんどん指摘していただけると幸いです。
やり方
rebase
したのちにコミットにreword
を指定します。
詳しく解説します。
1. rebase -i
を実行する
まずはrebase -i
を実行します。
git rebase -i HEAD~5 // HEADから5つ前のコミットまで
実行すると以下のような画面になると思います。
pick aca1de2 commit1
pick bfh2ea1 commmmmit2 // このコミットを変更したい
pick 1abef2e commit3
//# Commands:
//# p, pick <commit> = use commit
//# r, reword <commit> = use commit, but edit the commit message
//# e, edit <commit> = use commit, but stop for amending
//# s, squash <commit> = use commit, but meld into previous commit
//# f, fixup [-C | -c] <commit> = like "squash" but keep only the previous
//# commit's log message, unless -C is used, in which case
//# keep only this commit's message; -c is same as -C but
//# opens the editor
//# x, exec <command> = run command (the rest of the line) using shell
//# b, break = stop here (continue rebase later with 'git rebase --continue')
//# d, drop <commit> = remove commit
//# l, label <label> = label current HEAD with a name
//# t, reset <label> = reset HEAD to a label
//# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
//# . create a merge commit using the original merge commit's
//# . message (or the oneline, if no original merge commit was
//# . specified); use -c <commit> to reword the commit message
2. 変更したいコミットにreword
を指定する
次に変更したいコミットにreword
を指定します。
pick aca1de2 commit1
reword bfh2ea1 commmmmit2 // このコミットを変更したい
pick 1abef2e commit3
そして:wq
で終了すると、以下のような画面になります。
commmmmit2
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# ..........
そこで正しいコミット名に修正して、保存してください。
commit
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# ..........
ログを確認すると、コミット名が修正されていると思います。
git log --oneline
aca1de2 commit1
bfh2ea1 commit2
1abef2e commit3
まとめ
コミット名を変更したいときは、rebase
してreword
を指定しましょう