7

I have a specific commit on a GitHub repository from which I want to extract a patch to apply in a different place, similar what I would get when using git format-patch.

I am lazy or the repository is too big and I don't want to fetch the whole repository just to extract that patch.

How can I do this quickly?

usr1234567
  • 21,601
  • 16
  • 108
  • 128
batista
  • 181
  • 2
  • 10
  • 1
    Thanks for the links! I searched here and didn't get an answer, I still believe that it is relevant to have it on the stackoverflow knowledge base. – batista May 07 '14 at 19:03
  • Here, read this: http://stackoverflow.com/questions/how-to-ask. – Don Branson May 07 '14 at 19:06
  • 1
    I did it before. As I am sure you know, it is shown every time you ask a question, there is no need to be condescending with me. Nevertheless, I did it again just now to try and find where I am failing with the question. I even redid a search on the big search box, the [results](http://stackoverflow.com/search?q=patch+from+commit+GitHub) were not even close to my question. Besides the search part, I am on topic, am being specific and made the question relevant to others. The open mind part comes from accepting an answer that was focusing on diff instead of patch, but still addressed it. – batista May 07 '14 at 19:18
  • It doesn't seem like you followed this part: "Tell us what you found (on this site or elsewhere) and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers," in particular, "or elsewhere." 5 seconds on google would have given you your answer. – Don Branson May 07 '14 at 19:20
  • Fair point on the "or elsewhere" part. Still, there was no related question showing up in the search results here, so I think it was relevant to ask. Maybe this is becoming too meta, but I see SO as an evolving knowledge base, and not a pointer to google. Given my premise, would there have been a better way to ask it instead? – batista May 07 '14 at 19:35
  • "but I see SO as an evolving knowledge base, and not a pointer to google" I agree that SO's not supposed to be a list of pointers to other sites. I did not have the intention of being condescending. Tone can be hard to read, and I always have to search a bit to find the how-to-ask. As far as the question is concerned, I googled for it and found it right away. Usually that's the place to start with a question. I take it from SO's how-to-ask that the best questions are ones where the answer doesn't already exist elsewhere, or is flawed in some way. – Don Branson May 07 '14 at 19:40

1 Answers1

19
  1. Browse to the appropriate commit, e.g.

    https://github.com/github/gitignore/commit/e9552d855c356b062ed82b83fcaacd230821a6eb

  2. Edit the URL in your address bar and add .diff to the end, e.g.

    https://github.com/github/gitignore/commit/e9552d855c356b062ed82b83fcaacd230821a6eb.diff

  3. Copy and paste (or File > Save) the unified diff

You can also use .patch instead of .diff, which seems to generate input suitable for application with git am.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • 2
    Great, I was looking for the **patch**, then I can pipe it to `git am` directly with `curl`. `curl .patch | git am` Thanks! – batista May 07 '14 at 19:03