Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use git am to apply patches from email messages?

Tags:

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.

like image 597
DarkKnight Avatar asked Feb 21 '11 04:02

DarkKnight


People also ask

How do I apply a git am patch?

In order to apply a Git patch file, use the “git am” command and specify the Git patch file to be used. Referring to our previous example, make sure to check out to the branch where you want your patch file to be applied.

How does git am work?

git am is a super useful command which can be used for many things as it's reading and parsing the mailbox containing the commits you specify and allows you to use only parts of the extracted data such as the code diff, the autor, the message…

What is the difference between git am and git apply?

git apply takes a patch (e.g. the output of git diff ) and applies it to the working directory (or index, if --index or --cached is used). git am takes a mailbox of commits formatted as an email messages (e.g. the output of git format-patch ) and applies them to the current branch.


Video Answer


2 Answers

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 [email protected] [email protected] ... *.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.

like image 69
Cascabel Avatar answered Sep 17 '22 15:09

Cascabel


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.

like image 24
J-16 SDiZ Avatar answered Sep 19 '22 15:09

J-16 SDiZ