What is git send-email for?

Asked

Viewed 69 times

0

I’m needing to use git send-email to send an exercise via email, but I couldn’t understand the purpose of this command in git. Can I send the repository with the files via email? How it works?

  • It serves to send patches (fixes) by email. You will not be able to send files or the archive (Bundle). To use it, you must use the command git format-patch to prepare the corrections before they are sent (choose the commit, for example). To see an example of what you will receive in the email, run the command git format-patch --stdout <commit hash>

  • @Valdeirpsr, it would be nice for you to answer the question in the answer box, not the comment box, so we can mark it as a correct answer, or even "rank" if others answer!

  • @egomesbrandao In fact. It happens that, at the time I wrote, I could not do something more elaborate. I will try to make a more complete answer.

1 answer

2


Let’s go by part.

Purpose of the command send-email

GIT was born at a time when it was very common for programmers and enthusiasts to get together in communities and forums to debate and program. Although there are versioning software like the Bitkeeper, there wasn’t (as far as I know) an integrated Git system (launching in 2005) like Github, Gitlab and Bitbuket, for example.

Instead, some programmers used the command git send-email to send fixes and new codes through SMTP protocols. With this, they could share their codes and help the community.

How the command works?

Basically, it sends a collection of corrections made by you to a recipient who will be able to merge the changes.

Command allows one of the two types to be sent:

  • Format mbox (we will see below)
  • Format created by Greg Kroah-Hartman (Use at your own risk, author’s words )

Attachments can be sent with the command?

No. It only sends text. If you want to send your repository by email, just use the command git archive or git bundle.

How to send corrections via email?

Requirements

Preparing sending

Before sending, we need to prepare the corrections as in the example below.

git format-patch 0ac05bd5a72f8d4e6f2d7313689153851a4809e5

# Saída
# 0001-Update-.bash_aliases.patch
# 0002-Create-.functions.patch

Observing: To include a file, use the command git format-patch --root -- <file>

Contents of *.patch files

When opening or printing the contents of the file on the screen, we can see that it has the email headers (FROM, SUBJECT, DATE) and the body of the message stating where the changes occurred.

OBS.: The comments started with # do not exist in the original file and were added for didactic reasons

# Na linha abaixo temos o <commit-hash>
From 28f8dabbc894ec75a1d8bee86f9de18ad1e7ccd1 Mon Sep 17 00:00:00 2001

# Informações autor
From: Valdeir S. <[email protected]>

# Data de criação do <commit>
Date: Sat, 20 Mar 2021 16:17:48 -0300

# Assunto do <commit> (a primeira linha dele)
Subject: [PATCH 1/3] Update .bash_aliases

# Estatísticas das alterações
# Apresenta a quantidade de arquivos alterados, criados e deletados
# E a quantidade de caracteres removidos e adicionados
---
 .bash_aliases | 3 ---
 1 file changed, 3 deletions(-)

# Abaixo são destacadas as diferenças entre o snapshot anterior do arquivo com o atual
diff --git a/.bash_aliases b/.bash_aliases

# Index da árvore de trabalho.
# Compare `git show 450e3a9` com `git show 1cdcd5e`
index 450e3a9..1cdcd5e 100644
--- a/.bash_aliases
+++ b/.bash_aliases

# A linha iniciada com "-" significa que a linha foi removida
# A linha iniciada com "+" significa que a linha foi adicionada
# A linha iniciada SEM "-" e SEM "+" significa que não sofreu alterações
@@ -27,9 +27,6 @@ alias myip="dig +short myip.opendns.com @resolver1.opendns.com"
 # Outros
 alias diff="git diff --no-index"

-# Comandos
-command -v calc >> /dev/null || function calc(){ awk "BEGIN{ print $* }" ;}
-
 # Finaliza todos os containers do Docker
 function dockerStopAll() {
   for c in $(docker ps | tail -n +2 | cut -d' ' -f1); do
--
2.31.1.windows.1

Sending changes

To upload the patch collections, you can use an SMTP server/service. In the command below, we set our settings; however, they can be saved in the file ~/.gitconfig

git send-email \
  --smtp-encryption tls \
  --smtp-server smtp.mailtrap.io \
  --smtp-server-port 587 \
  --smtp-user <hash> \
  --smtp-pass <hash> \
  *.patch

Out of command

# Lista de arquivos
0001-Update-.bash_aliases.patch
0002-Create-.functions.patch
0003-refactor-remove-o-arquivo-de-configura-o-do-navegado.patch
(mbox) Adding cc: Valdeir S. <[email protected]> from line 'From: Valdeir S. <[email protected]>'

# Cabeçalho e corpo do e-mail
From: [email protected]
To: [email protected]
Cc: Valdeir S. <[email protected]>
Subject: [PATCH 1/6] Update-.bash_aliases.patch
Date: Mon, 12 Apr 2021 23:29:20 -0300
Message-Id: <[email protected]>
X-Mailer: git-send-email 2.31.1.windows.1
MIME-Version: 1.0
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|[e]dit|[q]uit|[a]ll):

If you want to send the changes, press y or to and ENTER

What is the command for format-patch

He is responsible for preparing the files by commit with the required headers and the output of the command git diff <commit B>..<commit A>.

What is MBOX?

According to the documentation of Freebsd, MBOX is "a text file that contains an arbitrary number of email messages. Each message consists of a postmark, followed by an email message formatted according to RFC822 and RFC2822. Lines are separated by line feed characters (ASCII 10)."

Someone, in their right mind, use this?

This is the only way to contribute to some projects like the Linux Kernel or GIT itself.

If someone is interested in contributing to the Kernel or just wants to know how to do it, just go to the page Sending fixes: the essential guide to the essential guide to putting your code in the kernel

Example of configuration in the file ~/.gitconfig

[sendemail]
    smtpEncryption = tls
    smtpServer = smtp.gmail.com
    smtpUser = [email protected]
    smtpServerPort = 587
    smtpPass = Your-pass (Não é recomendável)
    confirm = auto
    replyTo = [email protected]

More information

References

  • If you have suggestions (and mainly corrections of spelling, punctuation etc) accepted.. 00h12m

  • I think now you’ve had time! Very good!!! D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.