Git修改旧提交的时间

如果要更改最近6次提交的作者日期和提交者日期,可以使用交互式rebase:

git rebase -i HEAD~6
pick c95a4b7 Modification 1
pick 1bc0b44 Modification 2
pick de19ad3 Modification 3
pick c110e7e Modification 4
pick 342256c Modification 5
pick 5108205 Modification 6

# Rebase eadedca..5108205 onto eadedca (6 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit

对于要更改日期的所有提交,请将git status替换为edit(或仅更改为e),然后保存并退出编辑器。

您现在可以通过以ISO-8601格式指定作者日期和提交者日期来修改每个提交:

GIT_COMMITTER_DATE="2017-10-08T09:51:07" git commit --amend --date="2017-10-08T09:51:07"

第一个日期是提交日期,第二个日期是作者日期。

然后转到下一个提交:

git rebase --continue

重复此过程,直到您修改所有提交。 通过git status查看您的进展。

 
posted @ 2020-06-17 16:03  鸭子船长  阅读(8445)  评论(0编辑  收藏  举报