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?

JetBrains IDEでコミット履歴をgit rebase -i (--interactive)で編集する

Posted at

各種JetBrains IDE上でも、git rebase -i(--interactive)を行うことができます。

公式ドキュメントはこちら。


Beforeのような履歴を、Afterのような履歴に編集する例を示します。

Before After
スクリーンショット 2025-07-26 15.49.40.png スクリーンショット 2025-07-26 15.46.05.png

具体的には、

  • コミットメッセージが「moveme to first」なコミットを並び変えて、先頭へ来るようにする(「init project」の後へ来るようにする)
  • 以下の3個のコミットをsquashして一つにまとめる(squashする)
    • コミットメッセージが「added comment0」
    • コミットメッセージが「added comment1」
    • コミットメッセージが「added comment2」
  • コミットメッセージが「removeme this commit」なコミットを取り除く(dropする)

という編集を行います。


Gitウィンドウ(Version Controlウィンドウ)のLogタブを開きます。

  • macOS : ⌘Cmd + 9
  • Windows : Alt + 9

スクリーンショット 2025-07-26 15.38.51.png

編集する一番古いコミット、今回はコミットメッセージが「added comment0」のコミットを右クリックし、出てくるメニューの「Interactively Rebase from Here...」を選択します。

スクリーンショット 2025-07-26 15.39.47.png

次の様なウィンドウが開きます。

スクリーンショット 2025-07-27 12.51.05.png

まずは、

  • コミットメッセージが「moveme to first」なコミットを並び変えて、先頭へ来るようにする(「init project」の後へ来るようにする)

を行います。ウィンドウの左上、下図の赤枠で囲ったボタンを押してコミットの順番を並び替えます。
スクリーンショット 2025-07-27 12.53.10.png

3回押すと一番上に来て、並び替えるコミットの中で先頭に来ます。

スクリーンショット 2025-07-27 12.55.33.png

次は

  • 以下の3個のコミットをsquashして一つにまとめる
    • コミットメッセージが「added comment0」
    • コミットメッセージが「added comment1」
    • コミットメッセージが「added comment2」

を行います。

コミットメッセージが「added comment1」のコミットを右クリックし、出てくるメニューから「Squash」を選択します。

スクリーンショット 2025-07-27 12.57.45.png

Squash後のコミットメッセージを編集します。

スクリーンショット 2025-07-27 12.59.11.png

コミットメッセージが「added comment2」のコミットにも同じ操作を行います。

スクリーンショット 2025-07-27 13.00.54.png

  • コミットメッセージが「removeme this commit」なコミットを取り除く(dropする)

を行います。

コミットメッセージが「removeme this commit」のコミットを右クリックし、出てくるメニューから「Drop」を選択します。

スクリーンショット 2025-07-27 13.02.26.png

すると下図の様な状態になります。これで、

  • コミットメッセージが「moveme to first」なコミットを並び変えて、「init project」の後に来るようにする
  • 以下の3個のコミットをsquashして一つにまとめる(squashする)
    • コミットメッセージが「added comment0」
    • コミットメッセージが「added comment1」
    • コミットメッセージが「added comment2」
  • コミットメッセージが「removeme this commit」なコミットを取り除く(dropする)

という編集を行う準備ができました。下図の赤枠で囲った「Start Rebasing」を行なって、rebaseを行います。

スクリーンショット 2025-07-27 13.05.10.png

なお、場合によってはconflictが発生するので修正してください。

この操作により、Beforeのような履歴を、Afterのような履歴に編集できました。

Before After
スクリーンショット 2025-07-26 15.49.40.png スクリーンショット 2025-07-26 15.46.05.png
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?