Gitのコミット名を変更する
rebase
というコマンドが便利。
コミットした後だけど、コミット名を変更したい時がたまにある...
1.コミットログを確認する
$ git log
commit 57c9567e61742a1d009b57ac22583fc6a2eb044c Author: myname <myemail@myemail.com> Date: Mon Apr 11 15:58:48 2014 +0900 画像アップロード refs #14682 commit 56b36788aec499b5d1c3e8ebbc33e656024869679 Author: myname <myemail@myemail.com> Date: Mon Apr 11 14:54:00 2014 +0900 css調整 refs #14682 commit 5691c4a67152d45d26e94a2801173e6b8803ea8a Author: myname <myemail@myemail.com> Date: Mon Apr 11 14:35:58 2014 +0900 ルーティングの設定 refs #14682 commit 1252841e89d7aa5c7b5de4a1024581ftoab1328a Author: myname <myemail@myemail.com> Date: Mon Apr 11 10:18:37 2014 +0900 gem追加 refs #14682
2. コミットログを変更する
$ git rebase -i HEAD~4
これで最新4つのコミットを操作することができる。(4にした意味は特にない。)
1 pick 6902121 画像アップロード refs #14682 2 pick 1310e1a css調整 refs #14682 3 pick 38b8018 ルーティングの設定 refs #14682 4 pick 48e9601 gem追加 refs #14682 5 6 # Rebase e2f5245..57c9567 onto e2f5245 7 # 8 # Commands: 9 # p, pick = use commit 10 # r, reword = use commit, but edit the commit message 11 # e, edit = use commit, but stop for amending 12 # s, squash = use commit, but meld into previous commit 13 # f, fixup = like "squash", but discard this commit's log message 14 # x, exec = run command (the rest of the line) using shell 15 # 16 # These lines can be re-ordered; they are executed from top to bottom. 17 # 18 # If you remove a line here THAT COMMIT WILL BE LOST. 19 # 20 # However, if you remove everything, the rebase will be aborted. 21 # 22 # Note that empty commits are commented out
今回は「css調整 refs #14682」を変更したいので、該当コミットのpickをrewordに書き換えて、保存して終了(:wq
)する。
pick 1310e1a css調整 refs #14682 ↓↓↓ reword 1310e1a css調整 refs #14682
2. コミット名を書き換える
コミット名を書き換えて、保存して終了(:wq
)するとコミット名が変更される。
1 margin,paddingを調整/users.css.scss refs #14682 2 3 # Please enter the commit message for your changes. Lines starting 4 # with '#' will be ignored, and an empty message aborts the commit. 5 # rebase in progress; onto e2f5245 6 # You are currently editing a commit while rebasing branch 'update_users/index' on 'e2f5245'. 7 # 8 # Changes to be committed: 9 # modified: app/assets/stylesheets/users.css.scss 10 #