Changes

Jump to navigation Jump to search

Git patch

2,461 bytes added, 19:38, 21 July 2013
Created page with "== Patches == See [http://ariejan.net/2009/10/26/how-to-create-and-apply-a-patch-with-git/ this very nice post!] === Make some work === git checkout -b fix In the new fix b..."
== Patches ==
See [http://ariejan.net/2009/10/26/how-to-create-and-apply-a-patch-with-git/ this very nice post!]

=== Make some work ===
git checkout -b fix

In the new fix branch you can hack whatever you need to fix. Write tests, update code etc. etc.

When you’re satisfied with all you changes, it’s time to create your patch. We assume you made a few commits in the fix branch and did not yet merge it back in to the master branch.

Check you changes
git log --pretty=oneline -3

=== Create patches ===
Now create your patch, comparing to the master branch
git format-patch master --stdout > fix.patch

Normally, git would create a separate patch file for each commit, but that’s not what we want. All we need is a single patch file. This will create a new file fix.patch with all changes from the current branch (fix) against master.

Now, you have a patch for the fix you wrote. [[Bugs_and_development_wishes | Send it to the maintainer of the project.]]

== Applying the patch ==

=== In subversion ===
patch -p1 < fix.patch

=== In git ===
The maintainer will take some steps, to check everything goes smooth.<br>
First, we take a look at what changes are in the patch. You can do this easily with '''git apply'''.
git apply --stat fix.patch

This command does not apply the patch, but only shows you the stats about what it’ll do. <br>
After peeking into the patch file with your favorite editor, you can see what the actual changes are.

Next, you’re interested in how troublesome the patch is going to be. Git allows you to test the patch before you actually apply it.
git apply --check fix.patch
If you don’t get any errors, the patch can be applied cleanly. <br>
Otherwise you may see what trouble you’ll run into.

To apply the patch, I’ll use '''git am''' instead of git apply. <br>
The reason for this is that git am allows you to sign off an applied patch. This may be useful for later reference.
git am --signoff < fix.patch

Applying: Added specs to test empty poster URL behaviour
Applying: Added poster URL as part of cli output
Okay, patches were applied cleanly and you’re master branch has been updated. Of course, run your tests again to make sure nothing got borked.

In you git log, you’ll find that the commit messages contain a “Signed-off-by” tag.<br>
This tag will be read by Github and others to provide useful info about how the commit ended up in the code.

== See also ==
[[Category:Git]]
Trusted, Bureaucrats
1,382

edits

Navigation menu