Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

BooK (2612)

BooK
  {book} {at} {cpan.org}
http://paris.mongueurs.net/
Yahoo! ID: philippe_bruhat (Add User, Send Message)

Obfuscation [plover.com]. Pink [axis-of-aevil.net]. HTTP::Proxy [cpan.org]. YEF [yapceurope.org]. Fishnet [perl.org]. Kapow [cpan.org]. Cog's [perl.org] bitch [cpan.org]. Invitation [perl.org]. White [perl.org] Camel [perl.org]. Nuff' said.

Journal of BooK (2612)

Tuesday December 15, 2009
05:22 PM

git-move-dates

[ #40024 ]

As a Perl programmer and Open Source enthousiast, you probably sometimes contribute to Open Source projects. Maybe even (gasp!) during work hours. If your employer is jealous of your time, you probably do not want your commits to look like they were done during work hours (especially in tools like the GitHub Punch Card).

On the other hand, it doesn't make sense to not commit your changes, and lose the benefits of using Git, just so that the reality of when you worked on these tiny changes is not made public. (At that point, it would probably also make more sense to have an open discussion with your boss...)

The way Git handles history makes it really easy to change the date of commits on a local branch. When I first thought about it, my idea was to write some date manipulation code (move a bunch of commits from a time range to another with all kinds of fancy nooks and crannies) and manipulate the Git trees and commits myself.

Then I discovered git filter-branch, which is all about rewriting commits. And I realized that in the situation above, moving commits a few hours in the future (like ten minutes before actually using git push or git send-email) is largely sufficient.

The problem is that the code to move a bunch of commits one hour in the future looks like this:

    git filter-branch --commit-filter '\
      GIT_AUTHOR_DATE=`echo "$GIT_AUTHOR_DATE"|perl -pe'\''s/\d+/$&+3600/e'\''`;\
      GIT_COMMITTER_DATE=`echo "$GIT_COMMITTER_DATE"|perl -pe'\''s/\d+/$&+3600/e'\''`;\
      git commit-tree "$@"' -- <rev-list>

Which is impossible to remember, and painful to write.

So, lazy as a Perl programmer should be, I just wrote git-move-dates, that writes and runs the above type of command-lines for me. Useful options include --committer and --author (to change only one of the two existing dates), and options ranging from --seconds to --weeks to define the exact timespan of your commits' time-travels.

As with my other Git gadgets, the source is available from http://github.com/book/git-gadgets.

And remember: there's nothing wrong with rewriting history, as long as it's unpublished, local history. ;-)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • temporary changing time zone before commit can also do the trick of working in the past or the future :-)
    • Even simpler: just define the GIT_AUTHOR_DATE and GIT_COMMITTER_DATE environment variables before doing your commit. Git understand several formats for those two variables.