Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I ignore committing timezone information in my commit?

Tags:

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 information.

2013-11-07 02:31:41 +0545 <-- This committer is living in Nepal. Surely.
2013-11-04 12:58:36 -0600 <-- This committer is living in CST or Ecuador or Chili or ...
2013-10-31 10:36:36 +0700 <-- This committer is living in Indonesia or Thai or Mongolia or Laos or Australia or ...
:

I know it's possible to hide this by editing the output form (e.g. git: timezone and timestamp format), but this hides what's actually saved in github's repository, only from my eye. Each committer's timezone is surely saved in github's server.

So my questions:

  1. Why are committer's timezone needed for commits? What is it used for? Isn't UTC time enough?
  2. Are there any options to ignore MY computer's timezone setting when committing? I don't want to set my computer's timezone to UTC, only because git is implicitly committing it.
like image 240
Izumi Kawashima Avatar asked May 26 '14 16:05

Izumi Kawashima


People also ask

How do I hide commit time on github?

Hide commit history on Git Branch First, create a new temporary branch and checkout. Now, add all the current files to this temporary branch. Create a new commit. Rename the temporary branch to your old branch name.

Does git store time zones?

Git commits store both a Unix timestamp and a time zone offset for each commit.

How do you commit without committing a message?

On Windows this command git commit -a --allow-empty-message -m '' makes commit with commit message " '' ", so it is better to use this command instead: git commit -a --allow-empty-message -m "" .

What happens if commit without message?

Committing in Git without a message So if you don't have anything to commit, you will be told that there is nothing to commit without the text editor being opened. So if your text editor opens up after the command, there is definitely something to commit.


2 Answers

You can use this command to commit in UTC time:

git commit --date="`date --utc +%Y-%m-%dT%H:%M:%S%z`"

You can also alias it to a convenient name:

git config --global alias.commitutc '!git commit --date="$(date --utc +%Y-%m-%dT%H:%M:%S%z)"'

And do git commitutc.

For a more detailed explanation take a look at this blog post.

like image 161
Saeb Amini Avatar answered Sep 20 '22 16:09

Saeb Amini


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.

like image 20
Matt Johnson-Pint Avatar answered Sep 19 '22 16:09

Matt Johnson-Pint