Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
63
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

@wMETAw

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

まずはじめに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

完了!

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
63
Help us understand the problem. What are the problem?