githubgit-commitformat-patch

How to quickly get a patch from a specific commit in GitHub?


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?


Solution

    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.