Skip to contentSkip to conversation

git reflog write does not pick up user.name and user.email from config

PATCH In review Michael 4 participants 9 messages Sep 29, 2025 – Oct 1, 2025

lore
Share & tools
lore

Michael

author
#0 lore raw

Hi there!

I've been playing around with a toy project (an interactive step by step git tutorial that is just a repo) where I have been creating a reflog manually so far. I was happy to see the new reflog write feature and wanted to integrate it.

When comparing the results of my hand made reflog with the new git reflog write result I found some differences: It does not seem to pick up the "user.name" and "user.email" from the local git config.

Example:

```bash
git init example && cd example
git config --local user.name "C O Mitter"
git config --local user.email "[email protected]"

message="hi"
oid="0000000000000000000000000000000000000000"

# Setting env vars works as expected
GIT_COMMITTER_NAME="$(git config --get user.name)" \
  GIT_COMMITTER_EMAIL="$(git config --get user.email)" \
  git reflog write "refs/test_vars" "$oid" "$oid" "$message"

# Picking up the information from the local config does not work
unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
git reflog write "refs/test_no_vars" "$oid" "$oid" "$message"

# Since setting the env variables to the config value, no diff expected
# but:
diff .git/logs/refs/test_*
# 1c1
# < 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 Michael <[email protected]> 1759142076 +0200	hi
# ---
# > 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 C O Mitter <[email protected]> 1759142076 +0200	hi
```

Intuitively I would expect these values to be picked up from the local config instead of having to specify them in env variables. I didn't expect it to fall back to some system values, instead of git config. Is there a reason that this information is not used from the config? And if yes, could you set some config, so that it gets picked up?

Unfortunately my ability to understand C is too limited to grasp how git_committer_info works…

Thanks a lot for your work!
Michael

#1 lore raw

Hi Michael,

Quoted 39 lines · Michael

Hi there!

I've been playing around with a toy project (an interactive step by step git tutorial that is just a repo) where I have been creating a reflog manually so far. I was happy to see the new reflog write feature and wanted to integrate it.

When comparing the results of my hand made reflog with the new git reflog write result I found some differences: It does not seem to pick up the "user.name" and "user.email" from the local git config.

Example:

```bash
git init example && cd example
git config --local user.name "C O Mitter"
git config --local user.email "[email protected]"

message="hi"
oid="0000000000000000000000000000000000000000"

# Setting env vars works as expected
GIT_COMMITTER_NAME="$(git config --get user.name)" \
  GIT_COMMITTER_EMAIL="$(git config --get user.email)" \
  git reflog write "refs/test_vars" "$oid" "$oid" "$message"

# Picking up the information from the local config does not work
unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL
git reflog write "refs/test_no_vars" "$oid" "$oid" "$message"

# Since setting the env variables to the config value, no diff expected
# but:
diff .git/logs/refs/test_*
# 1c1
# < 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 Michael <[email protected]> 1759142076 +0200	hi
# ---
# > 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000 C O Mitter <[email protected]> 1759142076 +0200	hi
```
Quoted 5 lines

Intuitively I would expect these values to be picked up from the local config instead of having to specify them in env variables. I didn't expect it to fall back to some system values, instead of git config. Is there a reason that this information is not used from the config? And if yes, could you set some config, so that it gets picked up?

Thanks for this great bug report!

You're definitely onto something. The problem indeed is that we don't parse any of the configuration right now, but I agree a 100% that we really should.

The reason why I never noticed this issue is that our test suite by default sets both GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL. If set, we'll end up writing those into the reflog as expected. So it's a bit of a test gap we have.

Quoted 2 lines

Unfortunately my ability to understand C is too limited to grasp how git_committer_info works…

You't typically call it with repo_config(). So if you want to work on this, the below should work. Only thing that's missing would be a test to verify that the gitconfig is parsed now as well as a proper commit message to tie it all together.

Thanks!

Patrick

builtin/reflog.c +2 -0
index c8f6b93d60..40884787b9 100644
@@ -422,6 +422,8 @@ static int cmd_reflog_write(int argc, const char **argv, const char *prefix,
 	if (argc != 4)
 		usage_with_options(reflog_write_usage, options);
 
+	repo_config(repo, git_ident_config, NULL);
+
 	ref = argv[0];
 	if (!is_root_ref(ref) && check_refname_format(ref, 0))
 		die(_("invalid reference name: %s"), ref);
#2 lore raw

PATCH 1/1 builtin/reflog: respect user config in "write" subcommand

From: Michael Lohmann <[email protected]>

Previously, the reflog write command only recognized the environment variables GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL. It did not account for user.name and user.email settings from the Git configuration.

Since the test suite always sets these variables, it was unnoticed that not present, it would use the system config as defaults instead of the git config.

---
 builtin/reflog.c        |  2 ++
 t/t1421-reflog-write.sh | 11 ++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)
builtin/reflog.c +2 -0
index c8f6b93d60..40884787b9 100644
@@ -422,6 +422,8 @@ static int cmd_reflog_write(int argc, const char **argv, const char *prefix,
 	if (argc != 4)
 		usage_with_options(reflog_write_usage, options);
 
+	repo_config(repo, git_ident_config, NULL);
+
 	ref = argv[0];
 	if (!is_root_ref(ref) && check_refname_format(ref, 0))
 		die(_("invalid reference name: %s"), ref);
t/t1421-reflog-write.sh +10 -1
index 46df64c176..65fc4cae93 100755
@@ -101,10 +101,19 @@ test_expect_success 'simple writes' '
 		EOF
 
 		git reflog write refs/heads/something $COMMIT_OID $COMMIT_OID second &&
-		test_reflog_matches . refs/heads/something <<-EOF
+		test_reflog_matches . refs/heads/something <<-EOF &&
 		$ZERO_OID $COMMIT_OID $SIGNATURE	first
 		$COMMIT_OID $COMMIT_OID $SIGNATURE	second
 		EOF
+
+		sane_unset GIT_COMMITTER_NAME &&
+		sane_unset GIT_COMMITTER_EMAIL &&
+		git config --local user.name "Author" &&
+		git config --local user.email "[email protected]" &&
+		git reflog write refs/heads/something_new $ZERO_OID $COMMIT_OID first &&
+		test_reflog_matches . refs/heads/something_new <<-EOF
+		$ZERO_OID $COMMIT_OID Author <[email protected]> 1112911993 -0700	first
+		EOF
 	)
 '
 

base-commit: 821f583da6d30a84249f75f33501504d597bc16b

Signature · 1 line
2.51.GIT
#3 lore raw

Re: [PATCH] builtin/reflog: respect user config in "write" subcommand

Quoted 1 line · On Tue, Sep 30, 2025 at 11:14:11AM +0200, [email protected] wrote:

From: Michael Lohmann <[email protected]>

Is there any specific reason why the originating mail address and the author information disagree with one another? It makes it hard for us to verify that these mail addresses actually map to the same person.

Quoted 3 lines

Previously, the reflog write command only recognized the environment variables GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL. It did not account for user.name and user.email settings from the Git configuration.

Nit: we typically write our commit messages in the following style:

- We describe the problem in the present tense.

- We then proceed to describe why that problem exists. In our context, it's also relevant to explain why our tests didn't catch the issue.

- Finally, we use imperative mood to say how the problem is fixed, as if instructing the code to change.

Happy to provide more guidance here as needed.

Quoted 5 lines

Since the test suite always sets these variables, it was unnoticed that not present, it would use the system config as defaults instead of the git config.

Another tiny nit: This should be "Co-authored-by", with everything except the leading "C" being lower-case.

Quoted 14 lines
t/t1421-reflog-write.sh +2 -1
index 46df64c176..65fc4cae93 100755
@@ -101,10 +101,19 @@ test_expect_success 'simple writes' '
 		EOF
 
 		git reflog write refs/heads/something $COMMIT_OID $COMMIT_OID second &&
-		test_reflog_matches . refs/heads/something <<-EOF
+		test_reflog_matches . refs/heads/something <<-EOF &&
 		$ZERO_OID $COMMIT_OID $SIGNATURE	first
 		$COMMIT_OID $COMMIT_OID $SIGNATURE	second
 		EOF
+

t/t1421-reflog-write.sh test_expect_success 'simple writes' ' · line 118

Quoted 10 lines
t/t1421-reflog-write.sh +8 -0
+		sane_unset GIT_COMMITTER_NAME &&
+		sane_unset GIT_COMMITTER_EMAIL &&
+		git config --local user.name "Author" &&
+		git config --local user.email "[email protected]" &&
+		git reflog write refs/heads/something_new $ZERO_OID $COMMIT_OID first &&
+		test_reflog_matches . refs/heads/something_new <<-EOF
+		$ZERO_OID $COMMIT_OID Author <[email protected]> 1112911993 -0700	first
+		EOF
 	)
 '

I think it would be preferable to make this a separate test case.

Thanks for working on this!

Patrick

#4 lore raw

PATCH v2 1/1 builtin/reflog: respect user config in "write" subcommand

From: Michael Lohmann <[email protected]>

The reflog write recognizes only GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL environment variables, ignoring the user.name and user.email settings from the Git configuration.

The test suite sets these variables, so this behavior was unnoticed.

Ensure that the reflog write also uses the values of user.name and user.email if set in the Git configuration.

---
Thank you for your feedback! Is this better now or how could I improve it?

The reason why I sent it from my other email address was that originally I didn't expect to submit a patch. Since I sent the first email from the other address, I wasn't sure if it was easier to keep the context, but I didn't have the other perspective. Now sent from the git email.

Change compared to last version:
- aligned commit message with style guide
- created a separate test case

Michael

 builtin/reflog.c        |  2 ++
 t/t1421-reflog-write.sh | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+)
builtin/reflog.c +2 -0
index c8f6b93d60..40884787b9 100644
@@ -422,6 +422,8 @@ static int cmd_reflog_write(int argc, const char **argv, const char *prefix,
 	if (argc != 4)
 		usage_with_options(reflog_write_usage, options);
 
+	repo_config(repo, git_ident_config, NULL);
+
 	ref = argv[0];
 	if (!is_root_ref(ref) && check_refname_format(ref, 0))
 		die(_("invalid reference name: %s"), ref);
t/t1421-reflog-write.sh +19 -0
index 46df64c176..cf0e8608fe 100755
@@ -108,6 +108,25 @@ test_expect_success 'simple writes' '
 	)
 '
 
+test_expect_success 'uses user.name and user.email config' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		test_commit initial &&
+		COMMIT_OID=$(git rev-parse HEAD) &&
+
+		sane_unset GIT_COMMITTER_NAME &&
+		sane_unset GIT_COMMITTER_EMAIL &&
+		git config --local user.name "Author" &&
+		git config --local user.email "[email protected]" &&
+		git reflog write refs/heads/something $ZERO_OID $COMMIT_OID first &&
+		test_reflog_matches . refs/heads/something <<-EOF
+		$ZERO_OID $COMMIT_OID Author <[email protected]> 1112911993 -0700	first
+		EOF
+	)
+'
+
 test_expect_success 'can write to root ref' '
 	test_when_finished "rm -rf repo" &&
 	git init repo &&

base-commit: 821f583da6d30a84249f75f33501504d597bc16b

Signature · 1 line
2.50.1 (Apple Git-155)
#5 lore raw

Re: [PATCH v2] builtin/reflog: respect user config in "write" subcommand

Quoted 5 lines · [email protected] writes:

From: Michael Lohmann <[email protected]>

The reflog write recognizes only GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL environment variables, ignoring the user.name and user.email settings from the Git configuration.

Rephrasing ", ignoring" and everything after the sentence to something like

..., but forgot to honor the user.name and user.email configuration variables, due to lack of repo_config() call to grab these values from the configuration files.

would make it more obvious to readers what the right correction would be.

Quoted 7 lines

The test suite sets these variables, so this behavior was unnoticed.

Ensure that the reflog write also uses the values of user.name and user.email if set in the Git configuration.

This is not in general the right place to make repo_config() call, even though in the current shape of the program it happens to work.

This will start to matter once we start adding command line options to the program. We want the configured values read from the configuration to populate the in-core variables first, and then call parse_options() to allow command line arguments to override them.

In short, move the call above parse_options().

Another thing to consider is if we want to do this inside cmd_reflog(), not here. Once we add another subcommand that also records who did what, other than "write", to the "reflog" command, this starts to matter.

Quoted 14 lines
builtin/reflog.c +0 -0
 	ref = argv[0];
 	if (!is_root_ref(ref) && check_refname_format(ref, 0))
 		die(_("invalid reference name: %s"), ref);
t/t1421-reflog-write.sh +3 -0
index 46df64c176..cf0e8608fe 100755
@@ -108,6 +108,25 @@ test_expect_success 'simple writes' '
 	)
 '
 
+test_expect_success 'uses user.name and user.email config' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&

t/t1421-reflog-write.sh test_expect_success 'simple writes' ' · line 123

Quoted 10 lines
t/t1421-reflog-write.sh +10 -0
+	(
+		cd repo &&
+		test_commit initial &&
+		COMMIT_OID=$(git rev-parse HEAD) &&
+
+		sane_unset GIT_COMMITTER_NAME &&
+		sane_unset GIT_COMMITTER_EMAIL &&
+		git config --local user.name "Author" &&
+		git config --local user.email "[email protected]" &&
+		git reflog write refs/heads/something $ZERO_OID $COMMIT_OID first &&

It certainly is good to test _without_ environment. Shouldn't we also make sure that _with_ environment variables, these configured values are overriden with a separate test?

t/t1421-reflog-write.sh test_expect_success 'simple writes' ' · line 125

Quoted 2 lines
t/t1421-reflog-write.sh +2 -0
+		test_reflog_matches . refs/heads/something <<-EOF
+		$ZERO_OID $COMMIT_OID Author <[email protected]> 1112911993 -0700	first

This timestamp is from the above "test_commit", presumably? If we later add more tests _before_ this step and they used test_commit, would that screw this test up? It may make sense to say $GIT_COMMITTER_DATE instead of that timestamp here.

Quoted 9 lines
t/t1421-reflog-write.sh +4 -0
+		EOF
+	)
+'
+
 test_expect_success 'can write to root ref' '
 	test_when_finished "rm -rf repo" &&
 	git init repo &&

base-commit: 821f583da6d30a84249f75f33501504d597bc16b

Thanks.

#6 lore raw

PATCH v3 1/1 builtin/reflog: respect user config in "write" subcommand

The reflog write recognizes only GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL environment variables, but forgot to honor the user.name and user.email configuration variables, due to lack of repo_config() call to grab these values from the configuration files.

The test suite sets these variables, so this behavior was unnoticed.

Ensure that the reflog write also uses the values of user.name and user.email if set in the Git configuration.

---
- Improved commit message according to Junio Hamanos suggestion
- moved repo_config() call above parse_options() (I can't judge where the proper place would be)
- add test to check if env variables overwrite config
- use $GIT_COMMITTER_DATE instead of that timestamp in existing test case

 builtin/reflog.c        |  2 ++
 t/t1421-reflog-write.sh | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)
builtin/reflog.c +2 -0
index c8f6b93d60..dcbfe89339 100644
@@ -418,6 +418,8 @@ static int cmd_reflog_write(int argc, const char **argv, const char *prefix,
 	const char *ref, *message;
 	int ret;
 
+	repo_config(repo, git_ident_config, NULL);
+
 	argc = parse_options(argc, argv, prefix, options, reflog_write_usage, 0);
 	if (argc != 4)
 		usage_with_options(reflog_write_usage, options);
t/t1421-reflog-write.sh +36 -0
index 46df64c176..603ec3f6ed 100755
@@ -108,6 +108,42 @@ test_expect_success 'simple writes' '
 	)
 '
 
+test_expect_success 'uses user.name and user.email config' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		test_commit initial &&
+		COMMIT_OID=$(git rev-parse HEAD) &&
+
+		sane_unset GIT_COMMITTER_NAME &&
+		sane_unset GIT_COMMITTER_EMAIL &&
+		git config --local user.name "Author" &&
+		git config --local user.email "[email protected]" &&
+		git reflog write refs/heads/something $ZERO_OID $COMMIT_OID first &&
+		test_reflog_matches . refs/heads/something <<-EOF
+		$ZERO_OID $COMMIT_OID Author <[email protected]> $GIT_COMMITTER_DATE	first
+		EOF
+	)
+'
+
+test_expect_success 'environment variables take precedence over config' '
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+		test_commit initial &&
+		COMMIT_OID=$(git rev-parse HEAD) &&
+
+		git config --local user.name "Author" &&
+		git config --local user.email "[email protected]" &&
+		git reflog write refs/heads/something $ZERO_OID $COMMIT_OID first &&
+		test_reflog_matches . refs/heads/something <<-EOF
+		$ZERO_OID $COMMIT_OID $SIGNATURE	first
+		EOF
+	)
+'
+
 test_expect_success 'can write to root ref' '
 	test_when_finished "rm -rf repo" &&
 	git init repo &&

base-commit: 821f583da6d30a84249f75f33501504d597bc16b

Signature · 1 line
2.51.0.373.g6d4c29e8d5.dirty
#7 lore raw

Re: [PATCH v3] builtin/reflog: respect user config in "write" subcommand

Quoted 5 lines · Michael Lohmann

The reflog write recognizes only GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL environment variables, but forgot to honor the user.name and user.email configuration variables, due to lack of repo_config() call to grab these values from the configuration files.

Quoted 7 lines

The test suite sets these variables, so this behavior was unnoticed.

Ensure that the reflog write also uses the values of user.name and user.email if set in the Git configuration.

Thanks, this version looks good to me!

Patrick

#8 lore raw

Re: [PATCH v3] builtin/reflog: respect user config in "write" subcommand

Quoted 8 lines · Patrick Steinhardt
Quoted 7 lines · Michael Lohmann

The reflog write recognizes only GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL environment variables, but forgot to honor the user.name and user.email configuration variables, due to lack of repo_config() call to grab these values from the configuration files.

The test suite sets these variables, so this behavior was unnoticed.

Quoted 7 lines
Quoted 5 lines

Ensure that the reflog write also uses the values of user.name and user.email if set in the Git configuration.

Thanks, this version looks good to me!

Yup. Will apply on top of the ps/reflog-migrate-fixes topic.

I didn't realize "reflog write" was so new ;-)

Thanks.