Pages

Unixbhaskar's Blog

Wednesday, August 16, 2017

How to format patch and send patch by mail in Git

Well, these topic are littered on the internet. Still ,give you a detail ,what actually you need to do.

Step 1:

First and foremost thing, configure your git client like below:

The file you need to manipulate or put configuration in, should be in your home dir, the file name is :.gitconfig. I want you to only concentrate on sendmail part of it.

Here is how my .gitconfig file looks like :


[user]
email = yourmail@maildomain.com
name = Bhaskar Chowdhury
signingkey = yoursigninggpgkey
[push]
default = matching
[commit]
[gpg]
program = gpg2
[commit]
gpgsign = true
[core]
editor = vim
abbrev = 12
[color]
ui = true

[pretty]
fixes = Fixes: %h (\"%s\")
[log]
showSignature = true
[alias]
logline = log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit

[sendemail]
; setup for using git send-email; prompts for password
smtpuser = yourmail@maildomain.com
smtpserver = smtp.maildomain.com
smtpencryption = tls
smtpserverport = 587
smtppass = yoursmtppassword


Well, we need to create the patch in a specific format that git email understands that.That is next step:

Step 2:

We need to get into the directory, where we want to create the patch(in fact it is not necessary, if you specify the path of the file )



bhaskar@GentooLinux_20:03:57_Wed Aug 16:~/git-linux/AdminScripts>git format-patch -1
0001-linux-counter-machine-update.patch

bhaskar@GentooLinux_20:04:15_Wed Aug 16:~/git-linux/AdminScripts>ls -al 0001-linux-counter-machine-update.patch
-rw-r--r-- 1 bhaskar vboxusers 35358 Aug 16 20:04 0001-linux-counter-machine-update.patch


Okay, git format-patch sub-command is used to create the patch and the -1 stands for the last commit you did in that directory.

Likewise, you can pick up any commit, which supposes to create a patch on.

So, next, send the patch to the designated parties. Please go through the output below to understand how it works.



bhaskar@GentooLinux_20:11:42_Wed Aug 16:~/git-linux/AdminScripts>git send-email 0001-linux-counter-machine-update.patch
0001-linux-counter-machine-update.patch
The following files are 8bit, but do not declare a Content-Transfer-Encoding.
0001-linux-counter-machine-update.patch
Which 8bit encoding should I declare [UTF-8]?
To whom should the emails be sent (if anyone)? unixbhaskar@lycos.com
Message-ID to be used as In-Reply-To for the first email (if any)?
(mbox) Adding cc: Bhaskar Chowdhury from line 'From: Bhaskar Chowdhury '
(body) Adding cc: Bhaskar Chowdhury from line 'Signed-off-by: Bhaskar Chowdhury '

From: Bhaskar Chowdhury
To: unixbhaskar@lycos.com
Cc: Bhaskar Chowdhury
Subject: [PATCH] linux counter machine update
Date: Wed, 16 Aug 2017 20:12:13 +0530
Message-Id: <20170816144213.31205-1-unixbhaskar@gmail.com>
X-Mailer: git-send-email 2.13.0
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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): y
OK. Log says:
Server: smtp.googlemail.com
MAIL FROM:
RCPT TO:
RCPT TO:
From: Bhaskar Chowdhury
To: unixbhaskar@lycos.com
Cc: Bhaskar Chowdhury
Subject: [PATCH] linux counter machine update
Date: Wed, 16 Aug 2017 20:12:13 +0530
Message-Id: <20170816144213.31205-1-unixbhaskar@gmail.com>
X-Mailer: git-send-email 2.13.0
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Result: 250


The above git command uses a sub-command send-email to send the mail to the designated parties. It also takes the patch file name as an argument to it.

If you look at the output closely, you can see that I have added some mail id in CC block apart from the default recipient.Once it's done taking your input, whom to send the patch, it will ask you with the option to quit and send et al.

Now, you should go back to your inbox and see the patch there!

Here is how it looks like in my mailbox:


1 comment: