41
submitted 4 months ago* (last edited 4 months ago) by Kalcifer@sh.itjust.works to c/git@programming.dev

Git records the local timezone when a commit is made [1]. Knowledge of the timezone in which a commit was made could be used as a bit of identifying information to de-anonymize the committer.

Setting one's timezone to UTC can help mitigate this issue [2][3] (though, ofc, one must still be wary of time-of-day commit patterns being used to deduce a timezone).

References

  1. Git documentation. git-commit. "Date Formats: Git internal format". Accessed: 2024-08-31T07:52Z. https://git-scm.com/docs/git-commit#Documentation/git-commit.txt-Gitinternalformat.

    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.

  2. jthill. "How can I ignore committing timezone information in my commit?". Stack Overflow. Published: 2014-05-26T16:57:37Z. (Accessed: 2024-08-31T08:27Z). https://stackoverflow.com/questions/23874208/how-can-i-ignore-committing-timezone-information-in-my-commit#comment36750060_23874208.

    to set the timezone for a specific command, say e.g. TZ=UTC git commit

  3. Oliver. "How can I ignore committing timezone information in my commit?". Stack Overflow. Published: 2022-05-22T08:56:38Z (Accessed: 2024-08-31T08:30Z). https://stackoverflow.com/a/72336094/7934600

    each commit Git stores a author date and a commit date. So you have to omit the timezone for both dates.

    I solved this for my self with the help of the following 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"
    


Cross-posts:

you are viewing a single comment's thread
view the rest of the comments
[-] onlinepersona@programming.dev 8 points 4 months ago* (last edited 4 months ago)

Ah shit... I always assumed it was just a nix timestamp. What's the use of storing the timezone? :/

Anti Commercial-AI license

[-] Kalcifer@sh.itjust.works 4 points 4 months ago

What’s the use of storing the timezone?

Imo, mostly QoL.

[-] NostraDavid@programming.dev 1 points 4 months ago* (last edited 4 months ago)

Because if we are in different zones we could both commit around 09:00 local time, so then it would seem we both committed at the same instance in time, which we didn't.

If we were both running UTC it could work, I guess; otherwise the order of commits would stop making sense.

edit: unless you meant to auto-convert the local time to a unix timestamp, that could work. I'm overthinking stuff.

[-] Kalcifer@sh.itjust.works 4 points 4 months ago* (last edited 4 months ago)

I guess; otherwise the order of commits would stop making sense.

Fundamentally, Git doesn't require commits to be dated (I'm assuming some things about the protocol here — there might be something in the source code that does a check, but my point will still stand). Version control only cares about the changes from one thing to the next. The time at which the change occurred is irrelevant for this end. Things like committer names, committer emails, commit times, commit messages, etc. are QoL additions on top of what I view as the base git protocol. I'm not sure if there is an RFC which outlines Git in more detail, though. If someone is aware of such a standard, please share it.


unless you meant to auto-convert the local time to a unix timestamp, that could work. I’m overthinking stuff.

Personally, that's what I presumed they were referring to. Either that, or just storing a UTC time. Technically, I suppose storing UTC is effectively storing a timezone, but not in the sense of what this post is talking about.

this post was submitted on 31 Aug 2024
41 points (84.7% liked)

Git

2918 readers
1 users here now

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Resources

Rules

  1. Follow programming.dev rules
  2. Be excellent to each other, no hostility towards users for any reason
  3. No spam of tools/companies/advertisements. It’s OK to post your own stuff part of the time, but the primary use of the community should not be self-promotion.

Git Logo by Jason Long is licensed under the Creative Commons Attribution 3.0 Unported License.

founded 2 years ago
MODERATORS