[ACCEPTED]-How can I ignore committing timezone information in my commit?-timezone

Accepted answer
Score: 12

You can use this command to commit in UTC 3 time:

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

You can also alias it to a convenient 2 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 1 take a look at this blog post.

Score: 7

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

git commit --date 1401179025 -0700

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

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

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

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

git log --date=local

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

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

Score: 0

Why are committer's timezone needed for 4 commits? What is it used for? Isn't UTC 3 time enough?

The timezone is useful to figure 2 out the local time of the author/committer 1 doing the operation.

According to https://git-scm.com/docs/git-commit-tree#_date_formats:

Git internal format

It is <unix timestamp> <time zone offset>, where <unix timestamp> is
the number of seconds since the UNIX epoch. <time zone offset> is a
positive or negative offset from UTC. For example CET (which is 1 hour
ahead of UTC) is +0100.
Score: 0

Combining an answer to a totally different question and this question, I made the 3 following and added it to my ~/.bashrc (or ~/.zshrc depending 2 on the system).

This will result in all git commit operations being 1 run as UTC:

git()
{
    if [[ $# -ge 1 && "$1" == "commit" ]]
    then
        TZ=UTC command git "$@"
    else 
        command git "$@"
    fi
}
Score: 0

Ommiting the timezone in your commit is 10 also a important from the point of information security. The timezone 9 tells everybody in which timzone do you 8 live and in case security is important for you, you should omit these information.

Other 7 answers to this question focus on the author 6 date, but for each commit Git stores a author date and a commit date. So you have 5 to omit the timezone for both dates.

I solved 4 this for my self with the help of the following 3 Git alias:

[alias]
    co = "!f() { \
            export GIT_AUTHOR_DATE=\"$(date -u +%Y-%m-%dT%H:%M:%S%z)\"; \
            export GIT_COMMITTER_DATE=\"$(date -u +%Y-%m-%dT%H:%M:%S%z)\"; \
            git commit $@; \
            git log -n 1 --pretty=\"Autor: %an <%ae> (%ai)\"; \
            git log -n 1 --pretty=\"Committer: %cn <%ce> (%ci)\"; \
          }; f"

This alias outputs also after 2 the commit the important properties of this 1 commit, so that I can check them easily.

More Related questions