git压缩并保留上次提交的时间戳 [英] git squash and preserve last commit's timestamp
问题描述
考虑我有提交
... - A - B - C
如果我使用 git rebase -i
来将所有三个提交压缩为一个,我们可以
选择A
壁球B
壁球C
我看到结果提交 A
具有其原始时间戳。如何使它继承commit C
(最后一个)的时间戳?
我能想到的是 git commit --amend --date =< new_time>
,但是这种方式需要记住commit C
在压扁或来自reflog之前。
我发现最新提交的时间戳更合理,因为它显示了我实际完成提交中的工作的时间。 / p>
谢谢。
但有几个选择。这里有一个:
git commit --amend --date =$(git show -s --pretty = tformat:% ai< sha1-of-C>)
另一个:
git commit --amend -c< sha1-of-C>
后者会破坏您现有的提交信息,因此您必须重新编写它。
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.
这篇关于git压缩并保留上次提交的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!