How can I ignore committing timezone information in my commit?

前端 未结 3 1634
攒了一身酷
攒了一身酷 2020-12-29 06:19

Recently, I forked a repository hosted by github, with contributors spreading all over the world, and found out that the each commit log contains committer\'s timezone infor

3条回答
  •  误落风尘
    2020-12-29 07:01

    When committing, git stores the Unix timestamp (seconds since 1/1/1970 UTC), and the local offset of the committer. You can override the offset, but you also have to supply the date as well.

    git commit --date 1401179025 -0700
    

    Multiple formats are supported, as documented here. I prefer the ISO-8601 format, which is like this:

    git commit --date 2014-05-27T01:23:45-07:00
    

    You can set the offset however you like. Use zero for UTC. Personally, I think this is unnecessary. It actually reduces the amount of information in the log. You may only care about the exact moment in time, but perhaps one might also care what time it was for that particular committer. For example, maybe you'd like to know if that person committed early in the morning or late at night. If you don't store the local offset, then that information is lost, and storing it doesn't hurt.

    If your primary concern is that viewing the git log doesn't align all of the commits to a single time zone, consider adjusting the log output using the --date options on the log command:

    git log --date=local
    

    The above uses the commit offsets to adjust the commit date to your own local time zone.

    I didn't see anything that would adjust it to UTC directly, but you could set your own time zone to UTC and then use this command.

提交回复
热议问题