2
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?

git rebase -i で大量のコミットをまとめるときの Vim 操作メモ

Last updated at Posted at 2025-09-08

大量のコミットを git rebase -i でまとめたいときに便利な Vim 操作手順をご紹介します。
pick を fixup に置き換える作業を効率化できます。

$ git rebase -i origin/main

ここで開かれる Vim の画面でコミットを操作します。

pick a1b2c3d WIP: add user model
pick d4e5f6g fix: typo in variable name
pick h7i8j9k add user controller
pick l0m1n2o implement user service
pick p3q4r5s add tests for user service
pick t6u7v8w update README

# Rebase 1234567..t6u7v8w onto 1234567 (6 commands)
#
# Commands:
#  p, pick <commit> = use commit
#  r, reword        = use commit, but edit the commit message
#  e, edit          = use commit, but stop for amending
#  s, squash        = use commit, but meld into previous commit
#  f, fixup         = like "squash", but discard this commit's log message
#  x, exec <cmd>    = run command (the rest of the line) using shell
#  b, break         = stop here (continue rebase later with 'git rebase --continue')
#  d, drop          = 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)
#
# These lines can be re-ordered; they are executed from top to bottom.
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.

pickfixup に変更したい場合を例とします。
fixup と入力する時は f と省略しても良いです。

方法1: 1行ずつ確認して置換

  • j / k で上下に移動して、対象のコミット行までカーソルを移動する
  • カーソルを pick の行頭にあることを確認する
    • 0 で行頭へ移動
  • cwfixup<Esc> と入力
    • cw で単語削除
    • fixup と入力
    • <Esc> で確定
  • 次の対象に移動(+)
    • + で次の行の行頭へ移動
  • . (ドット)で直前の操作を繰り返す

方法2: 対話的にまとめて置換

  • :%s/pick/fixup/c
    • replace with fixup (y/n/a/q/l/^E/^Y)? と毎行質問される
      • y 置換する
      • n 置換しない(skip)
      • a 以降すべて置換
      • q 中断

コミットごとに選びながら置換したい場合におすすめです。

2
1
1

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
2
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?