git 2.54.0ではgit historyでコミットメッセージの修正が簡単にできるぞ!!

git 2.54.0では​git historyで​コミットメッセージの​修正が​簡単に​できるぞ!!

はじめに

2026/04/20 に​ git v2.54.0 が​リリースされました。​新しく​追加された​historyサブコマンドを​使ってみましたが、​便利だったので​紹介します。

12
$ git -v
git version 2.54.0

git historyに​ついて

マージコミットを​挟まない、​コミットメッセージの​変更や​コミットの​分割と​いった​簡単な​作業を​する​ために​特化した​コマンドだそうです。

提供されているのは​コミットメッセージを​変更する​ためのrewordsplitのみで​非常に​コンパクトな​コマンドです。

123
$git history -h
usage: git history reword <commit> [--dry-run] [--update-refs=(branches|head)]
   or: git history split <commit> [--dry-run] [--update-refs=(branches|head)] [--] [<pathspec>...]

実践

reword編

7c0bd10を​「書いた​2」に​したい​場合、
image

1234567
# 1. git historyを​実行
$git history reword 7c0bd10

# 2. 書いた​2に​変更

# 3. 結果を​確認
$git log --oneline

この​あとはrebaseと​同じくgit push --force-with-leaseなどを​実行してください。

rebase -i実行後の、pickを​別の​ワードに​書き換える​手間が​省けていいですね。

split編

赤枠の​コミットを​分割する​場合、

image

1
$git history split ae6482d

コマンドを​実行すると、git add -pのような​Uiが​表われて、​hunk毎に​分割するか​聞かれるので​y/nで​返答します。
※diffの​表示は​恐らく​deltaの​影響を​うけてます

image

hunkの​選択後、​2度コミットメッセージの​変更を​促されて、​先ほどの​コミットが​「分割!​分割!!!!」と​「feat(blog): show draft posts in dev mode with visual indicator」の​2つに​分割されました。

image

注意

This command is still marked as experimental, so its interface may evolve. Give it a try with git history reword and git history split, available in Git 2.54.

実験的機能で​インターフェースが​変更される​可能性が​ある​そうなので、​利用する​際には​ヘルプを​確認しましょう。

There are a couple of intentional limitations worth noting. The history command does not support histories that contain merge commits, and it will refuse to perform any operation that would result in a merge conflict. By design, git history is meant for targeted, non-interactive rewrites, not the kind of open-ended history rewriting typically relegated to git rebase –i.

マージコミットを​含む履歴には​対応しておらず、​マージコンフリクトが​発生する​可能性の​ある​操作は​実行できないようです。​そういった​場合は​今迄どおり、rebase--rebase-mergeフラグなどを​使う​必要が​ありそうです。

おわりに

gitの​コマンドを​覚えられない​自分でも​使えそうな​気が​してきました。​これは​いいぞ。