I try to set the committer date of the latest commit to its author date. Usually this works with git rebase --committer-date-is-author-date HEAD~1
. Unfortunately there is only one commit which means that I have to use --root
instead of HEAD~1
but git rebase --committer-date-is-author-date --root
does not set the committer date to the author date for some reason. What can I do?

- 1,359
- 2
- 11
- 39
-
1Try again your `git rebase --committer-date-is-author-date --root` with Git 2.19 (Q3 2018): that should now work. See [my answer below](https://stackoverflow.com/a/51918234/6309). – VonC Aug 19 '18 at 13:40
4 Answers
TL;DR just give me a command line that works
git filter-branch --env-filter 'export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"'

- 484
- 4
- 16
-
4but this doesn't sign the commits. How can it be modified to add a GPG signature like when running `git commit --amend --no-edit -n -S`? – gMale Aug 28 '20 at 08:42
-
To re-sign all of them you can run `git filter-branch -f --commit-filter 'git commit-tree -S "$@";' -- --all` afterwards to re-sign all of them again. – kiler129 Jan 13 '23 at 11:53
The bad news
Unfortunately git rebase --root
uses the interactive rebase code (because the non-interactive code cannot "replay" the root commit), and --committer-date-is-author-date
is actually a flag passed to git am
, which implements the simple non-interactive cases.
The good news
What git rebase
does, at a fundamental level, is copy some commits (with, usually, some sort of change made during the copying process), then point a branch name at the final such copied commit. If there is just one commit you want to change-while-copying, you can use git commit --amend
instead of git rebase
.1 If there is only one commit in the entire repository, there can only be one commit that you need to change-while-copying, so this case will apply.
Instead of --committer-date-is-author-date
, you will need to use the GIT_COMMITTER_DATE
variable to set the commit time stamp to some arbitrary value. You can also use --author
and/or --date
to override the author name and/or time-stamp. Hence:
t='2017-09-01 12:34:56'
GIT_COMMITTER_DATE="$t" git commit --amend --date="$t"
would set both time stamps to September 1st of 2017, at 12:34:56. (I used a shell variable t
here to avoid typing in the same time stamp twice.)
(Add --no-edit
if you don't want to edit the commit message. Remember that the new commit will use whatever is currently in the index! If you have changed the index since extracting the HEAD commit, you may want to copy the HEAD
commit to a temporary index first, and use that.)
1This assumes the change you want to make is, e.g., the commit message text or date or author or some such, rather than the commit's parent ID. The definition of a root commit is one with no parent ID, and git commit --amend
will continue to have no parent ID, which is what you want in this case.

- 448,244
- 59
- 642
- 775
-
3FYI: `--amend --no-edit --date="..."` sounds like a usecase which often be shortened as `-C sha` where SHA points to a commit-id from where we want to take the author-date, author-email and commit-message.. Unfortunatelly, `-C` does not touch the 'committer' part, so the env-variable is still needed for that part – quetzalcoatl Nov 02 '17 at 23:35
But
git rebase --committer-date-is-author-date --root
does not set the committer date to the author date for some reason.
Actually, it might set it correctly, starting from Git 23.19 (Q3 2018)
The "author-script
" file "git rebase -i
" creates got broken when we started to move the command away from shell script, which is getting fixed now.
See commit 5522bba, commit 67f16e3, commit 0f16c09, commit ca3e182 (31 Jul 2018) by Eric Sunshine (sunshineco
).
(Merged by Junio C Hamano -- gitster
-- in commit 1bc505b, 17 Aug 2018)
sequencer
: fix "rebase -i --root
" corrupting author header timestampWhen "
git rebase -i --root
" creates a new root commit, it corrupts the "author
" header's timestamp by prepending a "@
":author A U Thor <author@example.com> @1112912773 -0700
The commit parser is very strict about the format of the "
author
" header, and does not allow a "@
" in that position.The "
@
" comes fromGIT_AUTHOR_DATE
in "rebase-merge/author-script
", signifying a Unix epoch-based timestamp, however,read_author_ident()
incorrectly allows it to slip into the commit's "author
" header, thus corrupting it.One possible fix would be simply to filter out the "
@
" when constructing the "author
" header timestamp, however, a more correct fix is to parse theGIT_AUTHOR_DATE
date (viaparse_date()
) and format the parsed result into the "author
" header.
Since "rebase-merge/author-script
" may be edited by the user, this approach has the extra benefit of catching other potential timestamp corruption due to hand-editing.We can do better than calling
parse_date()
ourselves and constructing the "author
" header manually, however, by instead taking advantage offmt_ident()
which does this work for us.

- 1,262,500
- 529
- 4,410
- 5,250
-
1`git rebase --committer-date-is-author-date --root` prints a: `fatal: cannot combine am options with either interactive or merge options` (git version 2.21.0.windows.1). It is expected though: https://git-scm.com/docs/git-rebase#_incompatible_options – 40detectives Mar 19 '19 at 13:02
-
@40detectives Strange: it is incompatible with `--root` only when used in combination with `--onto` – VonC Mar 19 '19 at 15:29
git rebase --committer-date-is-author-date
works correctly with more recent git versions.
Note that on Ubuntu, it wasn't working with the apt
-installed version and I had to install a more recent version following this https://itsfoss.com/install-git-ubuntu/ .