0

How often should we do git comit --amend --date=now [target] especially when editing a commit while rebasing or doing a fixup? If the answer is always, is it OK to let existing commits that follow the amended commit keep their author dates which is now earlier than the amended one? Let's presume the commits aren't distributed elsewhere yet. This question also intends to be more philosophical than effectual. I'm also a consistency freak when it comes to this.

Also mind that newer commits can also be dependent to the amended commit so them having earlier dates is questionable.

1 Answer 1

2

I don't think you need to amend anything. Every commit in Git carries two timestamps:

  • Author date – this is the time the original change was created.
  • Commit date – this is the time when particular commit was created.

Git commit is authored once, but its commit date is changing every time the commit itself is changed (like rebase or amend). For example, let's say you've created a commit at 2022-05-11T12:34:56. Then the author date is set to that, as well as commit date. If later you rebase your commit, the author date stays as 2022-05-11T12:34:56, but the commit date changes to e.g. 2022-05-12T11:23:58.

There is also a separate information about author (the user that made the change) and committer (the user that created the commit). If you have a branch that your colleague contributed to and then you rebase that branch, then you colleague will be the author, but you will be the committer.

This is the default behavior. If you want to change authorship of a commit, look at https://git-scm.com/docs/git-commit/2.24.0#Documentation/git-commit.txt---reset-author

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.