Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply github commit / pull request as a patch

How can I apply the patch from github?

I tried to compile minisat, but I came across two issues from the compilation with clang.

The first issue is solved in this github commit, it's forked from the original github. As the change is minute, I could easily patched the code to work manually.

The second issue is solved in this github (https://github.com/niklasso/minisat/pull/17), but the patch is not applied to the original source. I could manually update the code by copying the modified files, but it would be better if I can pull this patch into my local directory. Is it possible to do that with github? If so, how to do it?

like image 722
prosseek Avatar asked Feb 12 '15 17:02

prosseek


People also ask

How do I make a pull request patch?

Every pull-request on GH can be downloaded as a beautiful mail-patch, just by appending ". patch" to the pr URL. This will generate a mail-formatted patch file, that is a little different from an usual patch file: It has e-mail metadata.

How do I create a patch from a commit?

In order to create Git patch file for a specific commit, use the “git format-patch” command with the “-1” option and the commit SHA. In order to get the commit SHA, you have to use the “git log” command and look for the corresponding commit SHA.

How do I pull a patch from GitHub?

You can append . patch to the URL of any pull request to get the patch file. So for the example above, open the URL https://github.com/KevinGimbel/blog-patch-example/pull/1.patch to see the plain text patch file.


1 Answers

github provides patches for individual commits and pull requests (though I can't find the documentation for this).

You can generate the patch url by simply appending .patch to the end of the original url.

So, use https://github.com/JWalker1995/minisat/commit/a8cef9d932552b2ec155d5e0d44d8fe0efa3a235.patch for the first, and https://github.com/niklasso/minisat/pull/17.patch for the second.

The general url github.com/original/url/id would become github.com/original/url/id.patch for generating the patch.

In terms of commands to run, this becomes

  1. Download the patches to your git repo

    wget --output-document=issue1.patch https://github.com/JWalker1995/minisat/commit/a8cef9d932552b2ec155d5e0d44d8fe0efa3a235.patch
    wget --output-document=issue2.patch https://github.com/niklasso/minisat/pull/17.patch
    
  2. Apply the patches

    git apply issue1.patch
    

    Check the changes, add and commit. Repeat the same for patch 2.

You can check this blog post for a nice tutorial around creating and applying patches.

like image 93
Anshul Goyal Avatar answered Sep 28 '22 01:09

Anshul Goyal