Alex Rivera | Logout

How do patches work in Git?

Asked 2010-01-17T19:30:35.077
30

I'm new to Git, but familiar with SVN. As a test I made a repository in a local directory with git init. Then I cloned the empty repository (over SSH using 127.0.0.1, which is another thing I wanted to test) to another local directory. I added some files in repository 2, I did git add * and finally git commit -a -m "First source code".

I now want to create a patch using git format-patch and apply it on repository 1. How do I do this? I know there's a manual, but these things are terribly complicated and make me wanna do certain things to my monitor.

Edit
Report

1 Answer

14

The easiest method to create patches from the last commit (or last few commits) is to use format-patch with a negative number indicating the number of commits to create patches for:

git format-patch -1

You'll get a patch file named after the commit description. The use am to insert it into another repository:

git am << name_of_patch_file
answered 2010-01-17T19:37:10.787

Your Answer