[Git] “remote: error: GH007: Your push would publish a private email address.” を解決する
私は過去のプロジェクトを整理していて、このようなエラーに出くわしました。
 
 ## 症状
GitHub に登録している private email アドレスを含むリポジトリがリモートに push されたため、下記のエラーが発生したようです。
“`prettyprinted
 % git push -u origin master
 Enumerating objects: 1557, done.
 Counting objects: 100% (1557/1557), done.
 Delta compression using up to 4 threads
 Compressing objects: 100% (645/645), done.
 Writing objects: 100% (1557/1557), 51.61 MiB | 241.00 KiB/s, done.
 Total 1557 (delta 889), reused 1530 (delta 870)
 remote: Resolving deltas: 100% (889/889), done.
 remote: error: GH007: Your push would publish a private email address.
 remote: You can make your email public or disable this protection by visiting:
 remote: http://github.com/settings/emails
 To github.com:DriftwoodJP/foobar.git
 ! [remote rejected] master -> master (push declined due to email privacy restrictions)
 error: failed to push some refs to ‘git@github.com:DriftwoodJP/foobar.git’
 “`
これはいつの頃からか追加された親切な機能です。
 ですので案内された管理画面 URL から「Block command line pushes that expose my email」をオフにしてはいけません。
## 設定を確認する
まず `–global` と `–local` の設定を確認する必要があります。
グローバル設定を確認します。
“`prettyprinted
 % git config –global user.name
 % git config –global user.email
 “`
必要に応じてローカル設定、つまり問題の起きたリポジトリの設定を確認します。
 (設定されていれば)当該ディレクトリの `.gitconfig` の設定値が表示されます。
“`prettyprinted
 % git config –local user.name
 % git config –local user.email
 “`
確認に利用したコマンドの後に新しい値を続けると設定を変更する事が出来ます。
“`prettyprinted
 % git config –global user.email foobar@users.noreply.github.com
 “`
この設定を変更すると、以後のコミットには新しく設定した値が利用される事となります。
## 過去のリポジトリ、歴史を書き換える
さて、最後にエラー原因となった既存リポジトリの内容を書き換えます。
branch 毎に下記を実行します。
 `DriftwoodJP` の部分はあなたの設定にして下さい。
“`prettyprinted
 % git filter-branch -f –env-filter “GIT_AUTHOR_NAME=’DriftwoodJP’; GIT_AUTHOR_EMAIL=’DriftwoodJP@users.noreply.github.com’; GIT_COMMITTER_NAME=’DriftwoodJP’; GIT_COMMITTER_EMAIL=’DriftwoodJP@users.noreply.github.com’;” HEAD
 “`
書き換わった事を `git log –pretty=full` やリポジトリブラウザで確認しましょう。
 今回最初に行った `git push -u origin master` を再実行して完了です。
## 最後に
このドキュメントは下記の素晴らしい記事を参考に作られました。
> * [Git の Commit Author と Commiter を変更する – Qiita](https://qiita.com/sea_mountain/items/d70216a5bc16a88ed932)
またこちらのドキュメントも理解に役立つかも知れません。
> * [Git – git-filter-branch Documentation](https://git-scm.com/docs/git-filter-branch)
## 補遺
> * [Git – 歴史の書き換え](https://git-scm.com/book/ja/v2/Git-%E3%81%AE%E3%81%95%E3%81%BE%E3%81%96%E3%81%BE%E3%81%AA%E3%83%84%E3%83%BC%E3%83%AB-%E6%AD%B4%E5%8F%B2%E3%81%AE%E6%9B%B8%E3%81%8D%E6%8F%9B%E3%81%88)
 > * [Git – git-commit-tree Documentation](https://git-scm.com/docs/git-commit-tree)
 > * [[Git] gitの歴史に残っているユーザー名やメールアドレスを書き換える | deadwood](https://www.d-wood.com/blog/2013/10/22_4900.html)
