Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to edit commit author without changing date?

Tags:

git

rebase

commit

I already know how to change the author of the commit (author and commit field),

git rebase --root --exec "git commit --amend --reset-author --no-edit"

but with the change of the author the dates (author date and commit date) are changed as of the current date. How do I save the old dates and change the author at the same time?

like image 209
JonyStack Avatar asked Jun 07 '26 00:06

JonyStack


2 Answers

I answer this here. In short:

git -c rebase.instructionFormat='%s%nexec GIT_COMMITTER_DATE="%cD" GIT_AUTHOR_DATE="%aD" git commit --amend --no-edit --reset-author' rebase -f <commit/branch before wrong author and email, or --root to rebase all>
like image 76
DharmaTurtle Avatar answered Jun 10 '26 03:06

DharmaTurtle


This is not a complete solution to your question, as the commit date is still updated (this does change the commit after all), but it might be suitable for anyone that just wants to keep the author date unchanged.

Rather than using --reset-author with also updates the author date, you can just set the author explicitly.

git rebase --root --exec "git commit --amend --author=John --no-edit"

You can specify what you want as the author explicitly, or use a use a search pattern (which is what the example above does).

--author=

Override the commit author. Specify an explicit author using the standard A U Thor format. Otherwise is assumed to be a pattern and is used to search for an existing commit by that author (i.e. rev-list --all -i --author=); the commit author is then copied from the first such commit found.

Source

like image 39
Jono Job Avatar answered Jun 10 '26 03:06

Jono Job



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!