Skip to content

Instantly share code, notes, and snippets.

@g-empr
Last active November 12, 2019 13:46
Show Gist options
  • Save g-empr/e2097081af4b9e0cf1d18234ce72f231 to your computer and use it in GitHub Desktop.
Save g-empr/e2097081af4b9e0cf1d18234ce72f231 to your computer and use it in GitHub Desktop.
複数のGitHubを扱う際のCommit Author/Commiterの管理.

Author と Committer

GitHubでpushしたとき、履歴にはアカウント情報が残る.
このとき、Author と Committer が別々に表示され非常に見づらくなることがある.
Author: オリジナルのコードを書いた人
Committer: コミットした人

そういう場合にはそれぞれの情報をまとめてPRなどを見やすくしよう.

手順

グローバルの設定

まず、よく使うアカウントの情報をグローバルに設定する.
以下のコマンドで自動生成され書き込まれる.

git config --global user.name name-of-account
git config --global user.email email@example.com

反映確認.

cat ~/.gitconfig

ローカルの設定

Git管理されているプロジェクトのディレクトリに移動する.

cd ~/dev/pj-dir

以下のコマンドでそのプロジェクト固有の情報を設定する.

git config --local user.name name-of-2nd-account
git config --local user.email 2nd-email@example.com
git commit --amend

反映確認.

cat .git/config

Authorを変更する

ローカルの設定をしたあと、各種プロジェクトにおいて適宜Authorの変更も行う.

git commit --amend --author="name-of-2nd-account <2nd-email@example.com>"
git rebase --continue
git log --pretty=full

pushが終わっている場合は -f 付きでpushし直す.

git push -f origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment