git squash and preserve last commit's timestamp

Consider I have commits

... -- A -- B -- C

If I use git rebase -i to squash all three commits into one, we could

  • Git merge commits between branches
  • “Keeping up” with remote master when working on a long-lived local topic branch
  • How to sort a json file by keys and values of those keys in jq
  • How does Git determine what objects need to be sent between repositories?
  • Should the .gitattributes file be in the commit?
  • Git with Cygwin - not accepting userinput for Username
  • pick A
    squash B
    squash C

    I see the resulted commit A has its original timestamp. How could make it inherit the timestamp of commit C (the last one)?

    What I can think of is git commit --amend --date=<new_time>, but this way needs to remember the timestamp of commit C before squash or from reflog.

    I find the timestamp of the latest commit is more reasonable, because it shows when I actually finished the work that are in the commits.


  • How to backup git server?
  • Git “does not appear to be a git repository”
  • Git move pull request from one repository to another repository
  • Cannot push to Git repository on Bitbucket
  • Git fatal: pack has bad object at offset X: inflate returned -5
  • Manage http access to git repositories using gitosis
  • 2 Solutions collect form web for “git squash and preserve last commit's timestamp”

    There’s not a trivial way to do this, but there are a few options. Here’s one:

    git commit --amend --date="$(git show -s --pretty=tformat:%ai <sha1-of-C>)"

    And another:

    git commit --amend -c <sha1-of-C>

    The latter will clobber your existing commit message, so you’ll have to rewrite it.

    git commit --amend --reset-author

    Git Baby is a git and github fan, let's start git clone.