format-patch: fix From header in cover letter

"git format-patch" takes "--from=<user ident>" command line option and uses the given ident for patch e-mails, but this is not applied to the cover letter, the option is ignored and the committer ident of the current user is used. This has been the case ever since "--from" was introduced in a9080475 (teach format-patch to place other authors into in-body "From", 2013-07-03). Teach the make_cover_letter() function to honor the option, instead of always using the current committer identity. Change variable name from "committer" to "from" to better reflect the purpose of the variable. Signed-off-by: Mirko Faina <mroik@delayed.space> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Mirko Faina committed Feb 18, 2026 at 00:25 UTC a8e89346a7731cb3104010f322c65e2a0c922618
3 files changed +17 -8
Documentation/git-format-patch.adoc
+6 -5
@@ -282,11 +282,12 @@ e.g., `--rfc='-(WIP)'` results in "PATCH (WIP)".
282
283 --from::
284 --from=<ident>::
285 - Use `ident` in the `From:` header of each commit email. If the
286 - author ident of the commit is not textually identical to the
287 - provided `ident`, place a `From:` header in the body of the
288 - message with the original author. If no `ident` is given, use
289 - the committer ident.
285 + Use `ident` in the `From:` header of each email. In case of a
286 + commit email, if the author ident of the commit is not textually
287 + identical to the provided `ident`, place a `From:` header in the
288 + body of the message with the original author. If no `ident` is
289 + given, or if the option is not passed at all, use the ident of
290 + the current committer.
291 +
292 Note that this option is only useful if you are actually sending the
293 emails and want to identify yourself as the sender, but retain the
builtin/log.c
+3 -3
@@ -1332,7 +1332,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
1332 int quiet,
1333 const struct format_config *cfg)
1334 {
1335 - const char *committer;
1335 + const char *from;
1336 struct shortlog log;
1337 struct strbuf sb = STRBUF_INIT;
1338 int i;
@@ -1345,7 +1345,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
1345 if (!cmit_fmt_is_mail(rev->commit_format))
1346 die(_("cover letter needs email format"));
1347
1348 - committer = git_committer_info(0);
1348 + from = cfg->from ? cfg->from : git_committer_info(0);
1349
1350 if (use_separate_file &&
1351 open_next_file(NULL, rev->numbered_files ? NULL : "cover-letter", rev, quiet))
@@ -1368,7 +1368,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
1368 pp.date_mode.type = DATE_RFC2822;
1369 pp.rev = rev;
1370 pp.encode_email_headers = rev->encode_email_headers;
1371 - pp_user_info(&pp, NULL, &sb, committer, encoding);
1371 + pp_user_info(&pp, NULL, &sb, from, encoding);
1372 prepare_cover_text(&pp, description_file, branch_name, &sb,
1373 encoding, need_8bit_cte, cfg);
1374 fprintf(rev->diffopt.file, "%s\n", sb.buf);
t/t4014-format-patch.sh
+8
@@ -1472,6 +1472,14 @@ test_expect_success '--from uses committer ident' '
1472 test_cmp expect patch.head
1473 '
1474
1475 +test_expect_success '--from applies to cover letter' '
1476 + test_when_finished "rm -rf patches" &&
1477 + git format-patch -1 --cover-letter --from="Foo Bar <author@example.com>" -o patches &&
1478 + echo "From: Foo Bar <author@example.com>" >expect &&
1479 + grep "^From:" patches/0000-cover-letter.patch >patch.head &&
1480 + test_cmp expect patch.head
1481 +'
1482 +
1483 test_expect_success '--from omits redundant in-body header' '
1484 git format-patch -1 --stdout --from="A U Thor <author@example.com>" >patch &&
1485 cat >expect <<-\EOF &&