Hack Your Design!

【git】直前の数個のコミットの歴史を著作者とともに修正する

たとえばこんなケース。

のびた君の努力の成果である直前の3つのコミットをジャイアンのコミットとして歴史を改変してみましょう。rebaseにて実現できます。

$ git rebase -i HEAD~3

こんな画面が出てきますので、

pickをeditにします。

こんなメッセージ。

Stopped at e4269d9... modify file1.
You can amend the commit now, with
    git commit --amend
Once you are satisfied with your changes, run
    git rebase --continue

HEADは3つ前になってます。 (ここで使っている "git lga" コマンドはこちらを参考

$ git lga
* 5a0edde - (master) add nobita-text. (20 minutes ago) <nobita>
* 4a73401 - modify file2. (20 minutes ago) <nobita>
* e4269d9 - (HEAD) modify file1. (20 minutes ago) <nobita>

1.amendオプションつけて、authorもジャイアンに改変します。

git commit --amend --author="jaian <jaian@doraemon.com>"

2.コミット後、rebase continueします。

git rebase --continue

1,2を繰り返します。

結果、のび太君の努力の歴史はジャイアンによって改変されました。

$ git lga
* 304d0c7 - (HEAD, master) add nobita-text. (16 seconds ago) <jaian>
* 66b5984 - modify file2. (34 seconds ago) <jaian>
* a0a26e2 - modify file1. (2 minutes ago) <jaian>

大成功☆(・ω<)

参考

6.4 Git Tools - Rewriting History

  • このエントリーをはてなブックマークに追加