Skip to content

Instantly share code, notes, and snippets.

@andreia
Created August 17, 2025 18:37
Show Gist options
  • Save andreia/591f8f0fbb1e82728e48c17acecf802e to your computer and use it in GitHub Desktop.
Save andreia/591f8f0fbb1e82728e48c17acecf802e to your computer and use it in GitHub Desktop.
Create a Git patch file

Create a patch file from uncommitted changes

If you only changed files (no staged changes yet):

git diff > my-changes.patch

If you also staged some changes (git add):

git diff --cached > my-changes.patch

If you want both staged + unstaged:

git diff HEAD > my-changes.patch

Create a patch from committed changes

To create a path with committed changes:

git format-patch -1 HEAD

The -1 flag indicates how many commits should be included:

    -<n>
         Prepare patches from the topmost <n> commits.

Source: https://git-scm.com/docs/git-format-patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment