Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change timestamps while rebasing git branch

Tags:

git

git-rebase

Use --ignore-date:

git rebase --ignore-date

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

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
    

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.