コミットのAuthorDateとCommitDateを書き換える

enter image description here

つまづいたのでメモ

まずはじめにAuthorとCommiterについて整理

AuthorとCommiter

$ git log

commit 176eca240a37e7bfa3292eb99a0712aca23c3052
Author: yamada_taro <yamada_taro@mail.com>
Date:   Fri Jul 29 19:00:38 2016 +0900

$ git log --pretty=fuller でさらに細かく辿ると「Author」「Commit」がある

commit 176eca240a37e7bfa3292eb99a0712aca23c3052
Author:     yamada_taro <yamada_taro@mail.com>
AuthorDate: Fri Jul 29 19:00:38 2016 +0900
Commit:     yamada_taro <yamada_taro@mail.com>
CommitDate: Fri Jul 29 19:00:38 2016 +0900

項目の説明は以下の図の通り

項目 説明
Author: コミットの作者
AuthorDate: コミット時間
Commit: リポジトリにコミットした人
CommitDate: コミット時間

AuthorとCommitが二つある理由は、
rebaseによる歴史の改ざんやcherry-pickした場合に、作者を残しておきたい為らしい。

ちなみに、オプション無しのgit logで表示される Date:AuthorDate: が表示されている

過去を改変する

rebase時にAuthorDateを好きな日時に変更し、CommitDateもそれに合わせる

$ git rebase -i HEAD~数字

#pick を edit に修正

# AuthorDateを変更する
$ git commit --amend --date="Fri Jul 29 16:00:00 2016 +0900"
$ git rebase --continue

# CommitDateをAuthorDateに合わせる
$ git rebase HEAD~数字 --committer-date-is-author-date
commit 234fcf0536052314fa83790009f4e30e19478706
Author:     yamada_taro <yamada_taro@mail.com>
AuthorDate: Fri Jul 1 15:10:34 2016 +0800
Commit:     yamada_taro <yamada_taro@mail.com>
CommitDate: Wed Jul 29 14:52:29 2016 +0900

↓↓↓↓

commit 11bbe54af0bd926978e0fe918508bf5b614e63a9
Author:     yamada_taro <yamada_taro@mail.com>
AuthorDate: Wed Jul 29 16:00:00 2016 +0900
Commit:     yamada_taro <yamada_taro@mail.com>
CommitDate: Wed Jul 29 16:00:00 2016 +0900

完了!strong text

0 件のコメント :

コメントを投稿