LoginSignup
20
15

More than 3 years have passed since last update.

git のauthor と committer を 変更

Last updated at Posted at 2019-12-30

ブログの動機

 うっかりして、会社のPCでプライベートのGitにコミットしてしまうと、authorcommiterが会社のものになってしまいます!:frowning2::frowning2:
その度にauthorcommiterを修正するのですが、肝心のコマンドが直ぐに思い付かずググっていました。。。もう二度とググりたくないと誓い、自分用のメモとしてまとめます。

gitコミットログを確認

$ git log --pretty=full
commit 186543f9bece44383ab973dc0253946bf09b159f
Author: 会社の <会社の@example.com>
Commit: 会社の <会社の@example.com>

    commit message2

commit 25ddf087cfe17f7f71c1fd273eed931b39c71a4b
Author: 自分の <自分の@example.com>
Commit: 自分の <自分の@example.com>

    commit message1

authorのみ変更

git rebase -i <修正したいコミットの一個前のコミットハッシュ>
例えば、commit message2authorを変更するなら

1. git rebase -i 25ddf087cfe17f7f71c1fd273eed931b39c71a4b

で修正したい対象のpick -> edit

2. git commit --amend --author="自分の<自分の@example.com>"

3. git rebase --continue

authorとcommitter両方変更する

git configを修正

configを正しい状態に設定する。
local configを確認する方法:
git config --local --list

$ git config --local user.name 自分の
$ git config --local user.email 自分の@example.com

ログを修正

1.git rebase -i <commit hash>

2.git commit --amend --reset-author これを実行することで、一発でcommiterとauthorが修正できる

3.git rebase --continue

4.git log --pretty=full で正しく修正されたのを確認

これで正しく修正できた:v:

 補足

一番最初のコミットを修正する際は、
git rebase -i --root <commit hash>
でやります。

20
15
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
20
15