vscodeでrewordしてコミットのコメントを修正する

2020年12月21日

vscodeでrewordしてコミットのコメントを修正する

vscodeでコミット時のコメントを修正する方法を書いておきたいと思います。

参考:gitのコミットの歴史を改変する(git rebase) 1 / 2

rewordしてコミットのコメントを修正する

下記のようなコミット履歴があるとします。
コメントの「sasisusesoとツイキしました。」を「sasisusesoと追記しました。」に修正したいと思います。

1.修正したいコメントより前のコミット履歴を右クリックする。
2.「Rebase current branch on this Commit」をクリックする。
3.「Launch Interactive Rebase in new Terminal」にチェックを付ける。
4.「Yes, rebase」をクリックする。

エディタに下記のようなコミット履歴が表示されます。
(選択されたコミットより新しいコミット履歴)


pick f01073f kakikukekoと追記しました。
pick dc81677 sasisusesoとツイキしまた。
pick 3e7c82c tatitutetoと追記しました。
pick fa71c37 naninunenoと追記しました。

# Rebase 094fcfd..fa71c37 onto 094fcfd
#
# 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
#
# 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
"/home/.git/rebase-merge/git-rebase-todo" 22L, 798C

該当するコミット履歴の「pick」を「reword」または「r」に書き換えます。
書き換え後は下記の通りです。


pick f01073f kakikukekoと追記しました。
r dc81677 sasisusesoとツイキしまた。   
pick 3e7c82c tatitutetoと追記しました。
pick fa71c37 naninunenoと追記しました。

「:wp」で保存して閉じると下記の通り、またエディタが立ち上がりコメントの修正を求められるので下記の通りに修正します。
【修正前】


sasisusesoとツイキしまた。# -> sasisusesoを追記しました。

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# HEAD detached from f01073f
# You are currently editing a commit while rebasing branch 'master' on '094fcfd'.
#
# Changes to be committed:
#   (use "git reset HEAD^1 ..." to unstage)
#
#       modified:   git_project/small_alphabets.txt

【修正後】


sasisusesoと追記しまた。

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# HEAD detached from f01073f
# You are currently editing a commit while rebasing branch 'master' on '094fcfd'.
#
# Changes to be committed:
#   (use "git reset HEAD^1 ..." to unstage)
#
#       modified:   git_project/small_alphabets.txt

「:wq」で保存して閉じると下記の通りコメントが修正されたのが確認できました。

YouTube

2020年12月21日