9

I am sending patches using git send-email <patch-name>.

I want that the email sent with the patch to have some additional text added at the top, besides the commit message.

Is there any way to do this?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Daniel Băluţă
  • 1,255
  • 11
  • 13
  • Git 2.18 (Q2 2018) now (7 years later) offers an official way to do this. See [my answer below](https://stackoverflow.com/a/50670983/6309) – VonC Jun 03 '18 at 21:07

3 Answers3

5

You can use --annotate, then just add your comment between the two --- of the patch, it won't affect the very patch.

Ref: https://kparal.wordpress.com/2011/08/03/git-tip-of-the-day-introduction-text-when-emailing-patches/

eg:

From 7ea3c50fa83950549de11c6834c465bc8f28b52b Mon Sep 17 00:00:00 2001
From: James Laska
Date: Mon, 1 Aug 2011 09:53:16 -0400
Subject: [PATCH] compose_tree - Save the setup.sh script for later debugging

---
This patch is really really important, because otherwise the 
world will end in 2012. Please accept it.

 tests/compose_tree/compose_tree.sh |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/tests/compose_tree/compose_tree.sh b/tests/compose_tree/compose_tree.sh
index 66ecefd..c2e041d 100755
--- a/tests/compose_tree/compose_tree.sh
+++ b/tests/compose_tree/compose_tree.sh
... (the rest of the patch)
Jason Chen
  • 121
  • 1
  • 4
  • 1
    There is also an option to make `--annotate` the default: `git config --global sendmail.annotate true`. Personally, I'm more tempted to just open the patch file on my text editor to review it and add the comment before calling `git send-email`. – Ciro Santilli OurBigBook.com May 03 '18 at 10:54
2

Documentation says that you can add --compose option to git send-email to "Invoke a text editor to edit an introductory message for the patch series."

If you want to automate this action and generate some text by your script. You could set $GIT_EDITOR environment variable to your script. It will receive temporary file name for the text in the command line argument. Contents of this file will be inserted into the message after your script exit.

Command for git send-email will look like:

$GIT_EDITOR="/path/to/your/script" git send-email ...

And your script could look like:

#!/bin/bash

echo "Your message" > $1
lig
  • 3,567
  • 1
  • 24
  • 36
  • 1
    But what happens if I have single patch. Not a patch series? – Daniel Băluţă Dec 16 '11 at 08:21
  • I think that a single patch is a patch series consisting of that one patch. Feel free to try it yourself. – lig Dec 16 '11 at 08:57
  • 1
    No. I don't want a separate email just to send an introductory message for a single patch. – Daniel Băluţă Dec 18 '11 at 00:23
  • @DanielBăluţă I didn't understand your comment. There is patch series that you want to email. There is solution to add message body text to the one email message that will be sent. This message will contain all of the patches. If your patch series consists from only one patch then this one email will contain your single patch and provided message body. – lig Dec 18 '11 at 08:50
1

Git 2.18 (Q2 2018) offers an alternative to --annotate or --compose for adding additional text when sending an email with git send-email.

See commit 04c4a4e (04 May 2018) by Drew DeVault (SirCmpwn).
Helped-by: Eric Wong (ele828).
(Merged by Junio C Hamano -- gitster -- in commit 89be19d, 30 May 2018)

git-send-email: allow re-editing of message

When shown the email summary, an opportunity is presented for the user to edit the email as if they had specified --annotate.
This also permits them to edit it multiple times.

"git send-email" can sometimes offer confirmation dialog "Send this email?" with choices 'Yes', 'No', 'Quit', and 'All'.
A new action 'Edit' has been added to this dialog's choice.

As seen in git-send-email.perl:

# If the user decides they want to make further edits, -1 is returned and the
# caller is expected to call send_message again after the edits are performed.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Note to self: this is my 10000th [tag:git] answer, a bit less than 10 years after mist [first answers like this one](https://stackoverflow.com/a/255212/6309) – VonC Jun 10 '18 at 07:38