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?

More than 3 years have passed since last update.

【Cloud9】一つ前にcommitしたcommitメッセージを修正したい!

Last updated at Posted at 2021-11-02

間違ってcommitしてしまった

今回の記事では、git add の後に間違って
git commit -m "コミットメッセージ"してしまった時の
修正方法について解説をしていきます。

備忘録として残していますが、
すごく簡単なので参考にしてください!

コマンド

まだリモートリポジトリにpushをしていなければ
一つ前のコミットメッセージの内容を修正できます。

ターミナル上でこのコマンドを入力してください。
ちなみにamendというのは英語で修正という意味になります。


ec2-user:~/environment/... (main) $ git commit --amend

すると、こんな画面がでてきます。


  GNU nano 2.9.8               /home/ec2-user/environment/workout/.git/COMMIT_EDITMSG                         

Merge pull request #41 from ***

[add] validation query color added to raty

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Author:    ***
# Date:      Tue Nov 2 11:59:25 2021 +0900
#
# On branch main
# Changes to be committed:
#       modified:   app/views/posts/edit.html.erb
#       modified:   app/views/posts/new.html.erb
#


[add] validation query color added to raty

今回の場合は↑がコミットメッセージになります。
これをカーソルを合わせて文字入力をすると修正できます。

入力が終わったら ctrl+xのexitを押します。
(windowsの場合のキーボード配列になります)

image.png

そうするとこの画面になるのでyを押します。
保存されてないように思いますがyを押した時点で上書きされます。

image.png

またこの画面に戻ることになるので、enterを
クリックしてください。
image.png

すると、ターミナルの画面に戻ってコミットメッセージの修正は
完了となりますよ!

修正が終わったら、適宜リモートリポジトリーにpushしてください♪

まとめ

以上、commitメッセージを修正するときの解説をしました!

・git commit --amendで一つ前のcommitの修正可能
・修正したいコミットメッセージを修正
・保存したらターミナルに戻りリモートへpushする。

もし参考になったらLGMTをぽちっと押してくれてら
励みになります!

それでは!チャオ!

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?