Chapters ▾ 2nd Edition

A3.9 附錄 C: Git Commands - Email


Many Git projects, including Git itself, are entirely maintained over mailing lists. Git has a number of tools built into it that help make this process easier, from generating patches you can easily email to applying those patches from an email box.

git apply

The git apply command applies a patch created with the git diff or even GNU diff command. It is similar to what the patch command might do with a few small differences.

We demonstrate using it and the circumstances in which you might do so in 套用從電子郵件來的補丁.

git am

The git am command is used to apply patches from an email inbox, specifically one that is mbox formatted. This is useful for receiving patches over email and applying them to your project easily.

We covered usage and workflow around git am in 使用 am 命令套用補丁 including using the --resolved, -i and -3 options.

There are also a number of hooks you can use to help with the workflow around git am and they are all covered in Email Workflow Hooks.

We also use it to apply patch formatted GitHub Pull Request changes in 電郵通知.

git format-patch

The git format-patch command is used to generate a series of patches in mbox format that you can use to send to a mailing list properly formatted.

We go through an example of contributing to a project using the git format-patch tool in 透過電子郵件貢獻到公眾專案.

git imap-send

The git imap-send command uploads a mailbox generated with git format-patch into an IMAP drafts folder.

We go through an example of contributing to a project by sending patches with the git imap-send tool in 透過電子郵件貢獻到公眾專案.

git send-email

The git send-email command is used to send patches that are generated with git format-patch over email.

We go through an example of contributing to a project by sending patches with the git send-email tool in 透過電子郵件貢獻到公眾專案.

git request-pull

The git request-pull command is simply used to generate an example message body to email to someone. If you have a branch on a public server and want to let someone know how to integrate those changes without sending the patches over email, you can run this command and send the output to the person you want to pull the changes in.

We demonstrate how to use git request-pull to generate a pull message in Fork 公眾專案.