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.
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.
format
or tformat
because the tformat
newline is stripped by the shell's command substitution rules. However, 99% of the time I want the final newline (or whatever the terminator is) because I'm usually parsing the custom log output with a script. In order to ensure that I habitually type tformat
when it matters, I use tformat
even when it doesn't matter - Richard Hansen 2012-04-05 04:38
git commit --amend --reset-author
tformat
- Crend King 2012-04-05 01:03