Help us understand the problem. What is going on with this article?

Git 古いコミットの日付だけ新しくする

More than 3 years have passed since last update.

コミットの順番を入れ替えたいことがある(バグを修正したあとテストを書いたが、 CI 上で再現テストのコミットを一度 fail させてから修正のコミットで pass することを示したい、など)

rebase -i でコミットの順番を入れ替えられるが、日付はオリジナルのコミット順のままなので、 git log の並び順が時系列にならなくてちょっと気持ち悪い。そういうときに、見た目と時系列を合わせる方法。

git commit --date オプションを使う。 --date=now と指定できて便利。
https://git-scm.com/docs/git-commit

reflog から cherry-pick -> 日付を変更して再び commit する場合

$ git cherry-pick c3fe8ff
[fix/XXXX 47e1d1d] Lorem ipsum dolor sit amet, consectetur adipisicing elit,
 Date: Fri Jan 15 16:30:34 2016 +0900
 1 file changed, 1 insertion(+), 1 deletion(-)

$ git commit --amend -C head --date=now
[fix/XXXX 4928054] Lorem ipsum dolor sit amet, consectetur adipisicing elit,
 Date: Fri Jan 15 16:55:11 2016 +0900
 1 file changed, 1 insertion(+), 1 deletion(-)

一度 stage し、改めて commit するとき前と同じ commit message を使いたい場合

# -C をつけると日付も指定した元 commit と同じになってしまうが...
$ git commit -C c3fe8ff
[fix/XXXX b454f1d] Lorem ipsum dolor sit amet, consectetur adipisicing elit,
 Date: Fri Jan 15 16:30:34 2016 +0900
 1 file changed, 1 insertion(+), 1 deletion(-)

# --date=now をつけると日付を変更してくれる(メッセージは同じものを再利用してくれる)
$ git commit -C c3fe8ff --date=now
[fix/XXXX 7c8d3eb] Lorem ipsum dolor sit amet, consectetur adipisicing elit,
 Date: Fri Jan 15 16:53:20 2016 +0900
 1 file changed, 1 insertion(+), 1 deletion(-)

元ネタ http://stackoverflow.com/questions/454734/how-can-one-change-the-timestamp-of-an-old-commit-in-git#comment8900550_5017265

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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした