gitemailgit-send-email

Send patches against first email through git send-email


I am currently working on a small assignment from an extra course in college. The task is to write a small program that does some work x, and a Makefile for it. We are to send the two files as a plain text email to our lecturer. We are then required to make a few changes to the program and send the changes as a patch to the first email. We are required to do this again.

Something like this:

program1 |--> patch for change2 |--> patch for change3

While i have no issues with the programming part, i'm having difficulty understanding how i could achieve this through git send-email. A detailed elucidation of the process for a beginner would be very much appreciated.


Solution

  • Now you've asked some specific questions:

    While i'm able to create the necessary patches for each of the sub assignments, i am unable to link all these three emails "somehow" in my lecturers mailbox

    This is more of an email question that a git question. Emails are generally "linked" by replying to a previous message; in most clients, such a chain of replies will be displayed as a "thread" of conversation.

    So after sending the first email, you would reply to it, possibly modifying the subject, and include the contents of the first patch (generated with git format-patch), and similarly for the second patch.

    You can actually do this from the command line using git format-patch and git send-email. First generate your patches:

    $ mkdir patches
    $ git format-patch -o patches master
    

    Then use git send-email to send these patches, taking advantage of the --in-reply-to command line option to link your messages to a previous message. This takes the message-id from a previous message as an argument, so you would need to look at your original message to get the value of the message-id header. Then you could run:

    git send-email \
      --in-reply-to ...message-id-here... \
      --from you@your.address \
      --to teacher@school.address \
      patches
    

    This will send two emails the subjects of which will look like:

    [PATCH 1/2] first line of commit message here
    

    And:

    [PATCH 2/2] first line of next commit message here
    

    For each email, git will prompt you whether or not you want to send it:

    From: lars@example.com
    To: lars@example.com
    Subject: [PATCH 1/2] made a patch
    Date: Thu,  3 Sep 2015 11:42:23 -0400
    Message-Id: <1441294944-28084-1-git-send-email-lars@example.com>
    X-Mailer: git-send-email 2.4.0
    In-Reply-To: <20150903153652.GE4975@example.com>
    References: <20150903153652.GE4975@example.com>
    
        The Cc list above has been expanded by additional
        addresses found in the patch commit message. By default
        send-email prompts before sending whenever this occurs.
        This behavior is controlled by the sendemail.confirm
        configuration setting.
    
        For additional information, run 'git send-email --help'.
        To retain the current behavior, but squelch this message,
        run 'git config --global sendemail.confirm auto'.
    
    Send this email? ([y]es|[n]o|[q]uit|[a]ll): 
    

    The first will be a reply to the original message, and the second patch will be a reply to the first. In my mail client, this looks like:

       1   4  sF 03-09-2015 To lars@exampl  Test message for git                                         (➥)
       2   4 N F 03-09-2015 To lars@exampl  └─>[PATCH 1/2] made a patch                               (✉ me)
       3   4 N F 03-09-2015 To lars@exampl    └─>[PATCH 2/2] hey look no hands                        (✉ me)
    

    (Note that for git to successfully send email you may need to provide it with some configuration. If it doesn't Just Work, git help send-email is the place to start.)