LoginSignup
27
15

More than 1 year has passed since last update.

Git | commit --amend を途中で取り消しする方法 (コミットメッセージ入力中のキャンセル)

Last updated at Posted at 2015-12-18

問題

アメンドするぜ!

$ git commit --amend

やっぱりやめたい!

Fix you brain

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# ...

保存せずに抜けるぜ!

:q! ( vim のコマンド )

うわあああ、コミットされてしまったああ!

 Date: Fri Dec 18 13:38:52 2015 +0900
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 you-need-amend.rb
 create mode 100644 but-i-walk-my-way.sh

解決策1

commit --amend

1.コミットメッセージをすべて削除する。

コミットメッセージが1行もない状態にする。(コメント行はあっても良い)

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Fri Dec 18 13:38:52 2015 +0900

ただし。空行・コメント行以外がひとつでもあるとコミットされてしまうので。
ファイル内容を全削除してしまった方が安全だろう。 ( d キーでも押しつつければ良い )

2.保存終了する

:x ( vim のコマンド )

3.結果

コミットされない。(元に戻る)

Aborting commit due to empty commit message.

解決策2

image

普通はどうなの?

amend ではない普通の commit では。
ただ保存せず終了すればOKのようだ。 ( :q! )

環境

  • git version 2.3.8 (Apple Git-58)
  • vim 7.3

余談

コミット編集中のメッセージで明確に説明されていたことに、後で気づいた。

an empty message aborts the commit.

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

メンター受付

27
15
4

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
27
15