はじめに
github(とかgit)使っていて
違うPCで作業した際にconfig設定さぼったばかりにcommitログの名前が意図しない名前になっちゃうときありますよね。
そんなときに名前やらアドレスやらを後から変更する対応メモ
現象
間違っているcommit履歴を確認
※ 一番直近のログが意図しないAuthorに
# git log
commit 964b4de2e3b7d9dc526c33b7a18e46e8f7451107
Author: hoge hoge <hoge.hoge@hoge-mac.local>
Date: Thu Mar 5 15:43:36 2015 +0900
first commit
commit 47fbd4d59c0e4216b4d70d3136014ee0905c0a98
Author: tweeeety <tweeeety@tweeeety.com>
Date: Thu Mar 5 13:59:37 2015 +0900
Initial commit
対応
対応方法としてはこちらをまんま参考にさせて頂きました。
→GitのCommit中のAuthor名およびCommitter名を変える
ローカルで反映
直近の1コミットだけでなく無条件ですべてのコミットを変更するので注意
# git filter-branch --commit-filter '
GIT_AUTHOR_NAME="tweeeety"
GIT_AUTHOR_EMAIL="tweeeety@tweeeety.com"
GIT_COMMITTER_NAME="tweeeety"
GIT_COMMITTER_EMAIL="tweeeety@tweeeety.com"
git commit-tree "$@"
' HEAD
※ この時点で確認してみる
# git log
commit 29335dd5abb37fa51a7fe98b9d982d6c8f949b2b
Author: tweeeety <tweeeety@tweeeety.com>
Date: Thu Mar 5 15:43:36 2015 +0900
first commit
commit 47fbd4d59c0e4216b4d70d3136014ee0905c0a98
Author: tweeeety <tweeeety@tweeeety.com>
Date: Thu Mar 5 13:59:37 2015 +0900
Initial commit
コマンドを叩いた後にログを見ると変わったように見えますが
これはローカルのcommit履歴だけ変更されているのでgithub上でcommitを見ると
変わっていないかと思います。
originに反映
ただpushするだけですがnon-fast-forwardで怒られたりするので
-fオプションで強制pushします
# git push -f origin master
githubで確認してみる
キャプチャ等は載せませんが、githubのcommit履歴が変わっていることを確認できれば間違いないでしょう。
恒久的な対応
今回は後から修正しましたが、そもそも最初に設定しておけば良いですね。
このあたりはいろんな記事に載ってるので詳細は割愛します。
git configコマンドで設定すればOKですね。
# cd [path_to_git_repos] # git config user.name "tweeeety" # git config user.email tweeeety@tweeeety.com ※ configを確認してみる # cat .git/config ・・・省略・・・ [user] name = tweeeety email = tweeeety@tweeeety.com
いちおう参考記事も。
→Gitコミットを任意の名前とメールアドレスで行うコマンド
終わり
他のPCで作業するって結構あるあるですよね。
なので後で使える自分用コピペ記事としてメモっておきましたー!