Git commit できない(Author identity unknown / who you are)
`user.name` と `user.email` が未設定だと commit が「Author identity unknown」で失敗する。
global もしくはリポジトリ単位で名前とメールを設定すればコミットできる。
#git#commit#config#identity
公開: 更新:
要約
git commit が次のように止まるのは、コミットの作者として記録する名前とメールアドレスが設定されていないためです。
git は誰がコミットしたかを必ず記録するので、user.name と user.email の両方が決まるまでコミットを作れません。
global に一度設定すれば、以降すべてのリポジトリで使い回せます。
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
fatal: unable to auto-detect email address (got 'user@host.(none)')よくある原因
- 新しい環境で未設定: OS を入れ替えた、別マシン、新しいユーザーなどで一度も設定していない。
- リポジトリ単位で空: global には設定があるのに、このリポジトリのローカル設定が優先されて空になっている。
.gitconfigが無い: CI のコンテナや最小構成の環境でホーム配下の設定ファイルが存在しない。- メール自動検出の失敗: ホスト名から推測したメールが無効で
unable to auto-detect email addressになる。
解決策
1. global に名前とメールを設定する
最も一般的なのは、マシン全体で使う値を global に設定する方法です。
git config --global user.name "Your Name"
git config --global user.email "you@example.com"設定後にもう一度 git commit を実行すれば通ります。
GitHub に公開したくない場合は、GitHub が提供する noreply メール(...@users.noreply.github.com)を使うとアドレスを隠せます。
2. リポジトリ単位で別の値を使う
仕事用と個人用でメールを分けたいときは、そのリポジトリ内で --global を付けずに実行します。
ローカル設定は global より優先されます。
cd path/to/repo
git config user.email "work@example.com"3. 反映を確認する
意図した値になっているかは次のコマンドで確認できます。
global とローカルのどちらが効いているかも分かります。
git config --list --show-origin | grep user
git config user.email