Change timezone for all commits in git history

I am converting an old CVS repository to git, which worked very well, except that all commits are in UTC instead of every local timezone of the author.

I would like to change the time zone of these commits based on each author, therefore, for example, everyone is fixed from one author change from +0000 to +1000, while commits from other authors are not changed. (This way, I can perform this procedure once for each author.)

The actual point in time should remain unchanged, so the commit, which is currently 02:00:00 +0000 , should become 12:00:00 +1000 .

Is this possible with something like git filter-branch ?

+5
source share
2 answers

I came up with this, which seems to do the trick:

 git filter-branch --env-filter ' if [ "$GIT_AUTHOR_EMAIL" == " email@example.com " ]; then export GIT_AUTHOR_DATE=`echo $GIT_AUTHOR_DATE | sed s/+0000/+1000/` fi if [ "$GIT_COMMITTER_EMAIL" == " email@example.com " ]; then export GIT_COMMITTER_DATE=`echo $GIT_COMMITTER_DATE | sed s/+0000/+1000/` fi' 

This changes the time zone for the email@example.com author from +0000 to +1000 . If the time zone is already something else in this commit, it will remain unchanged. If this person was the author, but not the committer (or vice versa), only the date of their role is updated.

It will not handle UTC offset changes due to DST, as @MattJohnson pointed out, but maybe you can add additional criteria for this if necessary.

This works using git's internal date format, which is always measured in seconds from the era and looks like @12345 +0000 . The time zone is not used here (the number of seconds is always in UTC), which allows you to change the time zone without changing the effective point in time to which reference is made. Changing the UTC offset here only affects the default date formatting.

+1
source

In addition to @Malvineous answer:

If you use the user's current time zone as a reference, you can use Git to convert the DST. This did the trick for me, fixing all the temporary fix points in the current time zone, including changing the DST.

 git filter-branch --env-filter ' if [ "$GIT_AUTHOR_EMAIL" == " email@example.com " ]; then GIT_AUTHOR_DATE=`echo $GIT_AUTHOR_DATE|sed -e "s/[+-][0-9]\{4\}//g"` fi if [ "$GIT_COMMITTER_EMAIL" == " email@example.com " ]; then GIT_COMMITTER_DATE=`echo $GIT_COMMITTER_DATE|sed -e "s/[+-][0-9]\{4\}//g"` fi ' 

The sed string disables the time zone. Git takes care of the rest.

Note that this does not support the explicit time zone, as originally requested, but takes care of the DST.

Note: In the original answer there were additional lines using date , e.g.

 GIT_AUTHOR_DATE=`date --date=$GIT_AUTHOR_DATE` 

However, this is not necessary because descriptors use the current time zone (including DST) when none are specified. Therefore, it is enough to cut the time zone.

+2
source

All Articles