Change timestamps while rebasing git branch

GitGit Rebase

Git Problem Overview


I have reorganized the commits in a branch before it is going to be made public causing the timestamps of the commits to be in an mixed up order. I would rather have them be all be today with only seconds in between.

Obviously these time stamps won't be correct either, but since this is the time when things go public I prefer that over a mixed up history, time-wise.

So how do I tell git to create new timestamps while rebasing?

Git Solutions


Solution 1 - Git

Use --ignore-date:

git rebase --ignore-date

Solution 2 - Git

In my case rebasing changed timestamps to CommitDate value, so in gitweb a bunch of months old commits showed up as 4 days old. I found the last commit with the correct date and did:

$ git rebase --committer-date-is-author-date SHA

Solution 3 - Git

There are the following ways

  1. Normal rebase

    git rebase --ignore-date
    
  2. Interactive rebase

    git rebase -i master
    git commit --amend --date=now
    git push origin <branch> -f
    

Solution 4 - Git

From comments:

> Incompatible with the --interactive option

Actually... it is no longer incompatible with Git 2.29 (Q4 2020): "git rebase -i"(man) learns a bit more options.
Options which are compatible with:

  • --interactive/-i
  • --root!

See commit 6160b2e (26 Aug 2020) by Junio C Hamano (gitster).
See commit 2712669 (17 Aug 2020), and commit ef484ad (13 Jul 2020) by Rohit Ashiwal (r1walz).
See commit a3894aa, commit 7573cec, commit e8cbe21 (17 Aug 2020) by Phillip Wood (phillipwood).
(Merged by Junio C Hamano -- gitster -- in commit 9c31b19, 03 Sep 2020)

> ## rebase -i: support --ignore-date
> Original-patch-by: Rohit Ashiwal
> Signed-off-by: Phillip Wood

> Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options. > > In particular the apply backend supports a number of options implemented by 'git am(man)' that are not implemented in the merge backend.
This means that the available options are different depending on which backend is used which is confusing. > > This patch adds support for the --ignore-date option to the merge backend. > > This option uses the current time as the author date rather than reusing the original author date when rewriting commits.
We take care to handle the combination of --ignore-date and --committer-date-is-author-date in the same way as the apply backend.

And:

> ## rebase: add --reset-author-date
> Helped-by: Junio C Hamano
> Signed-off-by: Rohit Ashiwal

> The previous commit introduced --ignore-date flag to rebase -i, but the name is rather vague as it does not say whether the author date or the committer date is ignored.
Add an alias to convey the precise purpose. > > ## --reset-author-date

Also:

> ## rebase -i: support --committer-date-is-author-date
> Original-patch-by: Rohit Ashiwal
> Signed-off-by: Phillip Wood

> This patch adds support for the --committer-date-is-author-date option to the merge backend.
This option uses the author date of the commit that is being rewritten as the committer date when the new commit is created.

git rebase now includes in its man page: > > ## --committer-date-is-author-date: > Instead of using the current time as the committer date, use > the author date of the commit being rebased as the committer > date.
> This option implies --force-rebase.

git rebase also includes in its man page: > ## --ignore-date: > This flag is passed to 'git am' to change the author date > of each rebased commit (see git am).


Note that in 2.29 (above), "--committer-date-is-author-date" option of "rebase" and "am" subcommands lost the e-mail address by mistake, which has been corrected with Git 2.29.1 (Q4 2020).

See commit 5f35edd, commit 16b0bb9, commit 56706db (23 Oct 2020) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit f34687d, 26 Oct 2020)

> ## am: fix broken email with --committer-date-is-author-date
> Signed-off-by: Jeff King

> Commit e8cbe2118a (am: stop exporting GIT_COMMITTER_DATE, 2020-08-17) rewrote the code for setting the committer date to use fmt_ident(), rather than setting an environment variable and letting commit_tree() handle it.
But it introduced two bugs: > - we use the author email string instead of the committer email > - when parsing the committer ident, we used the wrong variable to compute the length of the email, resulting in it always being a zero-length string
> > This commit fixes both, which causes our test of this option via the rebase "apply" backend to now succeed.

And:

> ## rebase: fix broken email with --committer-date-is-author-date
> Reported-by: VenomVendor
> Signed-off-by: Jeff King

> Commit 7573cec52c ("rebase -i: support --committer-date-is-author-date", 2020-08-17, Git v2.29.0-rc0 -- merge listed in batch #13) copied the committer ident-parsing code from builtin/am.c.
And in doing so, it copied a bug in which we always set the email to an empty string. > > We fixed the version in git-am in the previous commit; this commit fixes the copied code.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontarsiusView Question on Stackoverflow
Solution 1 - GitMichael Krelin - hackerView Answer on Stackoverflow
Solution 2 - GitlkraavView Answer on Stackoverflow
Solution 3 - GitUmar AsgharView Answer on Stackoverflow
Solution 4 - GitVonCView Answer on Stackoverflow