git commit実行時にエディターを開く際の開けないエラー(error: unable to start editor)になった時の対処

gitエラー解消
git commit実行時にエディターを開く際の開けないエラー(error: unable to start editor)になった時の対処
Memo
この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

git commit実行時にエディターを開く際の開けないエラー(error: unable to start editor)になった時の対処についてメモしました。

経緯

gitでコミット時間の変更を実施しようとした際に エディタが立ち上がらずエラーになってしまったため対処方を調査しました。

環境

  • Mac OS Big SUR 11.3.1
  • git 2.31.1

再現手順

コミットコマンドの実行

下記コミットコマンドを実行するとエラーが発生します。

terminal
$ git commit --amend --date="Mon Jul 13 18:00:00 2021 +0900" hint: Waiting for your editor to close the file... fatal: cannot run /usr/local/bin/apm: No such file or directory error: unable to start editor '/usr/local/bin/apm' Please supply the message using either -m or -F option.

Gitの設定を修正して解決

Gitの設定へcore.editorを設定することで解決します。

.gitconfigの確認

.gitconfigを表示しGitの設定を確認します。

terminal
$ cat ~/.gitconfig [user] email = XXXX.XXXX@gmail.com name = XXXX.XXXX

設定の追加

core.editorのオプションを付与ししてエディタの設定を追加します。

Vimへ変更

Vimへ変更する場合は下記のようにvimを追加します。

terminal
$ git config --global core.editor vim

VSCodeへ変更

VSCodeへ変更する場合は下記のように"code --wait"を追加します。

terminal
git config --global core.editor "code --wait"

その他

その他の場合も下記のようにエディタの箇所を置き換えて設定の変更を実施します。

terminal
git config --global core.editor "エディタ"

設定の確認

再度.gitconfigを表示しGitの設定を確認します。

terminal
$ cat ~/.gitconfig [user] email = XXXX.XXXX@gmail.com name = XXXX.XXXX [core] editor = vim

以上で完了です。

終わりに

最後までご覧いただきありがとうございます。
この記事ではgit commit実行時にエディターを開く際の開けないエラー(error: unable to start editor)になった時の対処について紹介させていただきました。

これからも皆様の開発に役立つ情報を提供していきたいと考えています。
今後ともよろしくお願いいたします。