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.

Leave a Comment