git squash and preserve last commit's timestamp
git
Solution
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.
Problem
Consider I have commits ``` ... -- A -- B -- C ``` If I use `git rebase -i` to squash all three commits into one, we could ``` 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. Thanks.