How to make a git rebase and keep the commit timestamp?

前端 未结 2 1660
长发绾君心
长发绾君心 2021-02-02 04:11

I want to make a rebase to remove a certain commit from my history. I know how to do that. However if I do it, the commit timestamp is set to the moment I completed the rebase.

2条回答
  •  囚心锁ツ
    2021-02-02 04:59

    So, here is a tedious way to do it (depending on how many commits you need to rebase), but I tried it out and it works. When you do an interactive rebase, mark each commit with "e" so that you can edit it. This will cause git to pause after every commit. At each pause, you can specify which date to use and continue to the next commit with:

    GIT_COMMITTER_DATE="Wed Feb 16 14:00 2011 +0100" git commit --amend   
    git rebase --continue
    

    This is, of course, a major pain in the rear, and you have to know all of the commit dates before hand, but if you can't do it any other way, it at least should work.

提交回复
热议问题