LoginSignup
111
79

More than 5 years have passed since last update.

gitのコミット時間を変更する

Last updated at Posted at 2017-09-16

まずはじめにAuthorCommiterについて整理

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="Wed Jan 10 23:59:59 2018 +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

完了!

111
79
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
111
79