如何更改Git中旧提交的时间戳? [英] How can one change the timestamp of an old commit in Git?
问题描述
解答如何修改现有的,unpushed提交?描述了一种方法来修改之前尚未推送到上游的提交消息。新消息继承原始提交的时间戳。这似乎是合乎逻辑的,但有没有办法重新设置时间? 使用 git filter-branch
,并设置了一个env过滤器,它为您希望解决的提交的特定散列设置GIT_AUTHOR_DATE和GIT_COMMITTER_DATE。
例如:
如果您想要更改提交<$的日期 c $ c> 119f9ecf58069b265ab22f1f97d2b648faf932e0 ,你可以这样做:
git filter-branch --env-filter \
'if $ [$ GIT_COMMIT = 119f9ecf58069b265ab22f1f97d2b648faf932e0]
then
export GIT_AUTHOR_DATE =Fri Jan 2 21:38:53 2009 -0800
export GIT_COMMITTER_DATE =Sat May 19 01:01:01 2007 -0700
fi'
The answers to How to modify existing, unpushed commits? describe a way to amend previous commit messages that haven't yet been pushed upstream. The new messages inherit the timestamps of the original commits. This seems logical, but is there a way to also re-set the times?
Use git filter-branch
with an env filter that sets GIT_AUTHOR_DATE and GIT_COMMITTER_DATE for the specific hash of the commit you're looking to fix.
This will invalidate that and all future hashes.
Example:
If you wanted to change the dates of commit 119f9ecf58069b265ab22f1f97d2b648faf932e0
, you could do so with something like this:
git filter-branch --env-filter \
'if [ $GIT_COMMIT = 119f9ecf58069b265ab22f1f97d2b648faf932e0 ]
then
export GIT_AUTHOR_DATE="Fri Jan 2 21:38:53 2009 -0800"
export GIT_COMMITTER_DATE="Sat May 19 01:01:01 2007 -0700"
fi'
这篇关于如何更改Git中旧提交的时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!