Gitコミットを任意の名前とメールアドレスで行うコマンド
git commit
を行う際、任意の名前・メールアドレスで行いたい時、ありませんか?
だからといって、以下のように一時的に変更して元に戻すのも面倒ですよね。
そんな時にオススメしたい方法、あるんです。
グローバル設定を変更する
ホームディレクトリ/.gitconfig
で定義する情報を変更するコマンド
$ git config --global user.name "John Doe" $ git config --global user.email johndoe@example.com
ローカルリポジトリ設定を変更する
リポジトリ/.git/config
で定義する情報を変更するコマンド
$ git config user.name "John Doe" $ git config user.email johndoe@example.com
ユースケース
sudo git commit -a
コマンドを利用している
いわゆる、コミットログがroot名義(Author: root <root@ホスト名>
)となる問題に悩まされている.gitconfig
や.git/config
の変更無しに任意の名義でコミットしたい
いちいち変えたり、元通りにするのは面倒ですよね・・・
などなど、シチュエーションは色々あると思います。
コマンド
はい、ここ重要ですよ。
--author
引数を利用して名前とメールアドレスを指定する事で、今回の課題も解決です。
git commit --author='Author Name <author@email.address.com>' -a
補足説明:
git log
で通常表示されるAuthorはこのコマンドで指定した通りになりますが、
以下のようにCommiterへは作用しません。問題となるケースは希だと思いますけども。
$ sudo git log commit fadb18b1771895b5fd8f11db63f7dd951decb67d Author: Author Name <author@email.address.com> Date: Sat Apr 20 00:23:08 2013 +0900 test commit $ sudo git log --pretty=full commit fadb18b1771895b5fd8f11db63f7dd951decb67d Author: Author Name <author@email.address.com> Commit: root <root@localhost> test commit