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 1 year has passed since last update.

root で git 操作しないとならんときのちょっと便利な小ネタ

0
Posted at

これなに

sudo git みたいなことをしないとならならい極々一部のインフラエンジニア向けの小ネタ。
小粒過ぎて誰も記事にしてないので書いてみた。

対象

sudo git commit みたいなことをしないとならないケースが若干ながらあり、その際にどうやってコミッターとオーサーを記録するか?という疑問を持ってる人。ニッチ。

注意

sudo -E についての是非はここでは取り扱いません。

結論(なんか TL;DR は正しくないらしいですね)

環境変数を正しく設定して、 sudo -E git でこの環境変数が正しく渡るようにしましょう。

GIT_AUTHOR_EMAIL=your_mail_address@example.com
GIT_AUTHOR_NAME=Your Name
GIT_COMMITTER_EMAIL=your_mail_address@example.com
GIT_COMMITTER_NAME=Your Name
GIT_CONFIG_GLOBAL=/path/to/your/gitconfig

解説

通常の sudo git commit では、コミッターとオーサーが root になってしまいます。
これを避ける設定が流石にどこかにあるだろ、あるはず! ...と思って探した結果、これらの環境変数にたどり着きました。

あとは -E オプション付きで sudo を実行し、ローカル環境変数を引き継いで git を実行しましょう。

$ sudo -E git commit -m '俺の仕業です`

なお、各環境変数について詳しくは下記に書いてあります。

  • GIT_CONFIG_GLOBAL について書かれてるドキュメントこれしかない?

  • こちらの一覧に GIT_CONFIG_GLOBAL が載ってないのでそのうち非推奨になるんかなー...
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?