git rebase -i

Pocket

rebase は便利

commitの順番を変えたい時

$ git rebase -i master

もしくはcommitの数だけ ~ を書く

$ git rebase -i HEAD~~~~

で今回は id renameのところに実はid rename2も入れたかったとする
git rebaseコマンドで下記のようにでてくる

pick 6879baf04 astel_app id rename
pick 925ca77d1 astel_app added uid_count
pick 6b6a9c3e6 astel_app id rename2

# Rebase a226abaaf..6b6a9c3e6 onto a226abaaf (3 commands)
#
# Commands:
# p, pick = 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 = run command (the rest of the line) using shell
# d, drop = remove commit
#
# 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.
#
# Note that empty commits are commented out

これを下のようにpickをfに書き換えて順番を入れ替える

pick 6879baf04 astel_app id rename
f 6b6a9c3e6 astel_app id rename2
pick 925ca77d1 astel_app added uid_count

# Rebase a226abaaf..6b6a9c3e6 onto a226abaaf (3 commands)
#
# Commands:
# p, pick = 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 = run command (the rest of the line) using shell
# d, drop = remove commit
#
# 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.
#
# Note that empty commits are commented out

こうなる

$ git log | head -n 30

commit 485d8653fba2d6cfdfaac647e917b1418c6c49e4
Author: astel <aaaaaaaastel@gmail.com>
Date:   Tue Jun 19 14:59:49 2018 +0900

    astel_app added uid_count

commit 502b0156492b272637b75dc6d40d74590f2d6ede
Author: astel <aaaaaaaastel@gmail.com>
Date:   Tue Jun 19 14:58:47 2018 +0900

    astel_app id rename

追記

直近のコミットコメントを消してもいいならf
(って書いてるやんけ

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください