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

Re: [PATCH] commit: add --committer option

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 10, 2025, 09:24 UTC
Message-ID
<aRGvVwRcsJA9CD9c@pks.im>
In-Reply-To
<pull.1997.git.1762683774166.gitgitgadget@gmail.com>
On Sun, Nov 09, 2025 at 10:22:54AM +0000, ZheNing Hu via GitGitGadget wrote:
Show 5 quoted lines
> From: ZheNing Hu <adlternative@gmail.com>
> 
> Add --committer option to git-commit, allowing users to override the
> committer identity similar to how --author works. This provides a more
> convenient alternative to setting GIT_COMMITTER_* environment variables.
Yeah, I can see how that's useful.
Show 13 quoted lines
> diff --git a/Documentation/git-commit.adoc b/Documentation/git-commit.adoc
> index 54c207ad45..a015c8328e 100644
> --- a/Documentation/git-commit.adoc
> +++ b/Documentation/git-commit.adoc
> @@ -12,7 +12,7 @@ git commit [-a | --interactive | --patch] [-s] [-v] [-u[<mode>]] [--amend]
>  	   [--dry-run] [(-c | -C | --squash) <commit> | --fixup [(amend|reword):]<commit>]
>  	   [-F <file> | -m <msg>] [--reset-author] [--allow-empty]
>  	   [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
> -	   [--date=<date>] [--cleanup=<mode>] [--[no-]status]
> +	   [--date=<date>] [--committer=<committer>] [--cleanup=<mode>] [--[no-]status]
>  	   [-i | -o] [--pathspec-from-file=<file> [--pathspec-file-nul]]
>  	   [(--trailer <token>[(=|:)<value>])...] [-S[<keyid>]]
>  	   [--] [<pathspec>...]
Nit: I'd move `--committer` before `--date` so that it comes directly
after `--author`.
Show 10 quoted lines
> @@ -181,6 +181,13 @@ See linkgit:git-rebase[1] for details.
>  `--date=<date>`::
>  	Override the author date used in the commit.
>  
> +`--committer=<committer>`::
> +	Override the committer for the commit. Specify an explicit committer using the
> +	standard `A U Thor <committer@example.com>` format. Otherwise _<committer>_
> +	is assumed to be a pattern and is used to search for an existing
> +	commit by that author (i.e. `git rev-list --all -i --author=<committer>`);
> +	the commit author is then copied from the first such commit found.
This matches the description of `--author`.
Show 53 quoted lines
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 0243f17d53..88e77cbaab 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -690,6 +691,48 @@ static void determine_author_info(struct strbuf *author_ident)
>  	free(date);
>  }
>  
> +static void determine_committer_info(struct strbuf *committer_ident)
> +{
> +	char *name, *email, *date;
> +	struct ident_split committer;
> +
> +	name = xstrdup_or_null(getenv("GIT_COMMITTER_NAME"));
> +	email = xstrdup_or_null(getenv("GIT_COMMITTER_EMAIL"));
> +	date = xstrdup_or_null(getenv("GIT_COMMITTER_DATE"));
> +
> +	if (force_committer) {
> +		struct ident_split ident;
> +
> +		if (split_ident_line(&ident, force_committer, strlen(force_committer)) < 0)
> +			die(_("malformed --committer parameter"));
> +		set_ident_var(&name, xmemdupz(ident.name_begin, ident.name_end - ident.name_begin));
> +		set_ident_var(&email, xmemdupz(ident.mail_begin, ident.mail_end - ident.mail_begin));
> +
> +		if (ident.date_begin) {
> +			struct strbuf date_buf = STRBUF_INIT;
> +			strbuf_addch(&date_buf, '@');
> +			strbuf_add(&date_buf, ident.date_begin, ident.date_end - ident.date_begin);
> +			strbuf_addch(&date_buf, ' ');
> +			strbuf_add(&date_buf, ident.tz_begin, ident.tz_end - ident.tz_begin);
> +			set_ident_var(&date, strbuf_detach(&date_buf, NULL));
> +		}
> +	}
> +
> +	if (force_date) {
> +		struct strbuf date_buf = STRBUF_INIT;
> +		if (parse_force_date(force_date, &date_buf))
> +			die(_("invalid date format: %s"), force_date);
> +		set_ident_var(&date, strbuf_detach(&date_buf, NULL));
> +	}
> +
> +	strbuf_addstr(committer_ident, fmt_ident(name, email, WANT_COMMITTER_IDENT, date,
> +				IDENT_STRICT));
> +	assert_split_ident(&committer, committer_ident);
> +	free(name);
> +	free(email);
> +	free(date);
> +}
> +
>  static int author_date_is_interesting(void)
>  {
>  	return author_message || force_date;

A lot of the infra in this new function is shared with `determine_author_info()`. It would be great if we could refactor it so that the common parts are shared given that this all is quite non-trivial.

Maybe we could have something like `determine_identity()` that contains the common bits between both functions? It might ultimately not really be worth it, but at least the functionality in the `force_committer` condition feels like it should be pulled out.

Show 10 quoted lines
> @@ -1321,6 +1364,9 @@ static int parse_and_validate_options(int argc, const char *argv[],
>  	if (force_author && renew_authorship)
>  		die(_("options '%s' and '%s' cannot be used together"), "--reset-author", "--author");
>  
> +	if (force_committer && !strchr(force_committer, '>'))
> +		force_committer = find_author_by_nickname(force_committer);
> +
>  	if (logfile || have_option_m || use_message)
>  		use_editor = 0;
>  

Is it the right thing to search by author here? Shouldn't we rather be searching by committer?

Show 8 quoted lines
> @@ -1930,8 +1978,13 @@ int cmd_commit(int argc,
>  		append_merge_tag_headers(parents, &tail);
>  	}
>  
> +	if (force_committer) {
> +		determine_committer_info(&committer_ident);
> +	}
> +
Nit: we tend to not use braces around single-line bodies.
Thanks!
Patrick
Previous: ZheNing Hu via GitGitGadgetNext: ZheNing Hu
Message 2 of 44 in “commit: add --committer option”
  1. commit: add --committer optionZheNing Hu via GitGitGadget, Nov 9, 2025
  2. Patrick SteinhardtNov 10, 2025
  3. ZheNing HuNov 10, 2025
  4. Junio C HamanoNov 10, 2025
  5. ZheNing HuNov 11, 2025
  6. Phillip WoodNov 10, 2025
  7. brian m. carlsonNov 10, 2025
  8. Jeff KingNov 10, 2025
  9. Junio C HamanoNov 10, 2025
  10. Patrick SteinhardtNov 11, 2025
  11. Phillip WoodNov 11, 2025
  12. ZheNing HuNov 12, 2025
  13. ZheNing HuNov 11, 2025
  14. Jeff KingNov 11, 2025
  15. Junio C HamanoNov 11, 2025
  16. Jeff KingNov 11, 2025
  17. Junio C HamanoNov 11, 2025
  18. Jeff KingNov 11, 2025
  19. ZheNing HuNov 12, 2025
  20. ZheNing HuNov 12, 2025
  21. ZheNing HuNov 12, 2025
  22. ZheNing HuNov 12, 2025
  23. ZheNing HuNov 12, 2025
  24. ZheNing HuNov 11, 2025
  25. Phillip WoodNov 11, 2025
  26. ZheNing HuNov 12, 2025
  27. Junio C HamanoNov 12, 2025
  28. ZheNing HuNov 15, 2025
  29. Junio C HamanoNov 16, 2025
  30. ZheNing HuNov 17, 2025
  31. Matej DujavaNov 16, 2025
  32. Phillip WoodNov 17, 2025
  33. ZheNing HuNov 17, 2025
  34. ZheNing HuNov 17, 2025
  35. commit: add --committer optionZheNing Hu via GitGitGadget, Nov 10, 2025
  36. Junio C HamanoNov 10, 2025
  37. Junio C HamanoNov 10, 2025
  38. ZheNing HuNov 11, 2025
  39. Junio C HamanoNov 11, 2025
  40. ZheNing HuNov 12, 2025
  41. commit: add --committer optionZheNing Hu via GitGitGadget, Nov 12, 2025
  42. Junio C HamanoNov 12, 2025
  43. ZheNing HuNov 15, 2025
  44. commit: add --committer optionZheNing Hu via GitGitGadget, Nov 15, 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.