Search code examples
mercurialrepositorycommit

How do I change commit time (not pushed yet)?


How can I change the time I've made a commit in my local repository?

Suppose I've done several commits and noticed that the date on my computer is wrong. Suppose also that these commits were not pushed anywhere yet.


Solution

  • You can do it easily with MQ (Mercurial Queues):

    Set up a bad date repo

    + hg init
    + echo line
    + hg commit -A -d 12/1 -m first
    adding file
    + echo line
    + hg commit -A -d 12/2 -m second
    + echo line
    + hg commit -A -d 12/3 -m third
    + hg log
    changeset:   2:81c88de729a8
    tag:         tip
    user:        Ry4an Brase <ry4an@mini>
    date:        Thu Dec 03 00:00:00 2009 -0600
    summary:     third
    
    changeset:   1:c1fe70008824
    user:        Ry4an Brase <ry4an@mini>
    date:        Wed Dec 02 00:00:00 2009 -0600
    summary:     second
    
    changeset:   0:abb97adaa541
    user:        Ry4an Brase <ry4an@mini>
    date:        Tue Dec 01 00:00:00 2009 -0600
    summary:     first
    

    Turn the changesets into patches in the queue

    + hg qimport -r 2
    + hg qimport -r 1
    + hg qimport -r 0
    

    Make each patch the qtip in turn and fix the date

    + hg qrefresh -D
    + hg qpop
    Now at: 1.diff
    + hg qrefresh -D
    + hg qpop
    Now at: 0.diff
    + hg qrefresh -D
    

    Reapply the patches

    + hg qpush
    applying 1.diff
    Now at: 1.diff
    + hg qpush
    applying 2.diff
    Now at: 2.diff
    

    Turn each patch back into real changesets

    + hg qdel -r 0
    + hg qdel -r 1
    + hg qdel -r 2
    

    All better:

    + hg log
    changeset:   2:6b51e14aadfc
    tag:         tip
    user:        Ry4an Brase <ry4an@mini>
    date:        Wed Feb 25 22:29:01 2009 -0600
    summary:     third
    
    changeset:   1:5cbb9fc51bcc
    user:        Ry4an Brase <ry4an@mini>
    date:        Wed Feb 25 22:29:02 2009 -0600
    summary:     second
    
    changeset:   0:ec58d1f24278
    user:        Ry4an Brase <ry4an@mini>
    date:        Wed Feb 25 22:29:02 2009 -0600
    summary:     first