29

I am pretty familiar with git(the basic stuff atleast-branches, merges,collaboration with peers etc.) but the other day a friend of mine told me that we could use git with our mailbox. The command involved is git am (manual page here).

Please could someone help me get started with git am.

philb
  • 2,031
  • 15
  • 20
DarkKnight
  • 660
  • 2
  • 8
  • 13
  • Are you on unix/linux or Windows? and will you actually use email, or do you have a network connection that could exchange patch files? – Philip Oakley Sep 16 '12 at 22:04
  • A complete answer might depend on 1) which email client you use 2) if you are subscribed to the mailing list where patches are sent, or not 3) the mailing list archive software used by the project.. – philb Jul 22 '21 at 02:13

4 Answers4

27

The other big thing involved is git format-patch. This will create the patches to be emailed; they can then be sent using git send-email or directly. For example:

# create a patch for each commit from origin's master to yours
git format-patch origin/master..master

# now send them... 
# there are a zillion options here, and also some configuration; read the man page
git send-email --to=maintainer@project.com --from=me@here.com ... *.patch

git am will accept the patches created by format-patch, and apply them sequentially, for example:

git am *.patch

You'll have to figure out how to export the patches in mbox format from your mail client yourself, though I suppose you could also simply send them as attachments or transfer them directly.

You can try this out for yourself entirely within one repository to see how it works. Create a set of patches as above, then check out the starting point, and use git am to apply the patches.

Cascabel
  • 479,068
  • 72
  • 370
  • 318
  • 1
    would i be able to run this from a hotmail or a gmail account? if so how? – DarkKnight Feb 21 '11 at 18:39
  • 2
    @DarkKnight: On which end? There are instructions for using gmail as the smtp server for `git send-email` in the manpage. On the other end... if the patches were sent as attachments, just save them all and apply exactly as I explained in my answer. If they're sent in-line, you can (in gmail) show the original message (dropdown at the top right), save it, delete the blank line at the top (not sure where that comes from), and run `git am` on it. – Cascabel Feb 21 '11 at 20:47
  • What client do you use to get messages in mbox format? – Ciro Santilli OurBigBook.com Mar 03 '18 at 09:39
  • Note that `git am *.patch` does not work with Windows command prompt. Be sure to use bash when running that command. See https://stackoverflow.com/a/60097534/468215 – esteuart Mar 12 '21 at 04:38
5

Patchwork workaround

https://github.com/getpatchwork/patchwork

Since no one seems to know how to convert emails to mbox with readily available tools, many of those cornerstone dinosaur projects projects have an associated, sometimes officially recommended, patchwork instance running, many of them hosted on https://patchwork.ozlabs.org/ e.g.:

Patchwork subscribes to the list, and parses the patches generated by git send-email, and allows you to download a patch.

So yes, yet another tooling layer on top of email...

Thunderbird export to mbox

Asked at: What is the easiest way to apply git series of patches from Thunderbird No answer so far.

See also

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
4

You need a mail client that can export mail as mbox file. Export the mails and run git-am your-mbox-file. It's done.

J-16 SDiZ
  • 26,473
  • 4
  • 65
  • 84
2

If the mailing list for the project you want to apply patches from uses public-inbox, which is the case for most Linux subprojects and Git, you can use b4 am tool to download the most recent version of a patch series and pipe it to git am:

b4 am -o- $url | git am

where url is the URL of any message in the thread.

philb
  • 2,031
  • 15
  • 20