git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: --reset-author does not reset author date when used in post-commit hook

From
DDDevste Devste <devstemail@gmail.com>
Date
Apr 1, 2025, 03:44 UTC
Message-ID
<CANM0SV0Np+52vjoopvAJ88U3Ue0EF35iarwBpOozrBH9KbH2Uw@mail.gmail.com>
In-Reply-To
<Z-s2p-ak-KpU6uaX@tapette.crustytoothpaste.net>
>your call to `git commit` will still invoke the
`prepare-commit-msg` (and possibly `commit-msg`) hook

Since I used --no-edit --no-verify in the example/hook, that shouldn't be the case though?

>such as by using an alias that sets `TZ=UTC0` to commit.

Unfortunately, (at least on Windows) most tools and IDEs don't even load a bashrc file (e.g. intellij) for their git UI, so that's not an option (and setting the TZ as a global environment variable has unwanted side effects, since it will set the timezone in various applications randomly, e.g. Electron/Slack will use the TZ for some but not for other things,...)

On Tue, 1 Apr 2025 at 02:43, brian m. carlson <sandals@crustytoothpaste.net> wrote:

Show 57 quoted lines
>
> On 2025-03-31 at 20:19:30, Devste Devste wrote:
> > device time zone is not UTC0
> >
> > post-commit hook:
> > if [[ -n "${SKIP_POST_COMMIT+x}" ]] && [[ "$SKIP_POST_COMMIT" -eq 1 ]]
> > then
> > exit
> > fi
> >
> > TZ=UTC0 SKIP_POST_COMMIT=1 git commit --amend --reset-author --no-edit
> > --no-verify --no-post-rewrite --allow-empty --quiet
> >
> > ---
> >
> > Run:
> > git commit -m "foo"
> > git show -s --format="Commit: %h%nAuthor: %an%nAuthor Date:
> > %ad%nCommitter: %cn%nCommitter Date: %cd%nMessage: %s%n" HEAD
> >
> > Expected that both Author Date: and Committer Date: show +0000 as
> > timezone. Only committer date shows +0000, while author date shows
> > time zone of device.
> >
> > When manually running the post-commit code (TZ=UTC0 SKIP_POST_COMMIT=1
> > ...) it correctly resets the author date to +0000 too
> >
> > When manually setting the date using --date="$(date +%s) +0000"
> > instead of  --reset-author it also works correctly in post-commit
> > hook.
>
> I can reproduce this, except that I had to use `TZ=America/Toronto`
> since my system is in UTC.  A quick look at the code led me to a guess
> that ended up correct.
>
> The `git commit` code sets `GIT_AUTHOR_NAME`, `GIT_AUTHOR_EMAIL`, and
> `GIT_AUTHOR_DATE`.  The latter contains a timezone identifier.  As a
> consequence, when the hook is invoked, those values are set in the
> environment, and the subsequent `git commit` in the hook uses them.  You
> can see this by placing something like `env >/tmp/foo` in your hook and
> then reading the output.
>
> I will say that this is definitely not the intended use of the
> post-commit hook and I am very much not surprised that this doesn't work
> as you intended.  You could certainly fix it by unsetting those
> environment variables, but I'd encourage you to adopt a different
> approach, such as by using an alias that sets `TZ=UTC0` to commit.  That
> will be more likely to work in the future and will definitely be less
> brittle.
>
> For instance, your call to `git commit` will still invoke the
> `prepare-commit-msg` (and possibly `commit-msg`) hook, which might
> result in unexpected changes to your message or even a failure of the
> second commit.
> --
> brian m. carlson (they/them)
> Toronto, Ontario, CA
Previous: brian m. carlsonNext: brian m. carlson
Message 3 of 5 in “--reset-author does not reset author date when used in post-commit hook”
  1. Devste DevsteMar 31, 2025
  2. brian m. carlsonApr 1, 2025
  3. Devste DevsteApr 1, 2025
  4. brian m. carlsonApr 1, 2025
  5. Devste DevsteApr 2, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.