Skip to content

Instantly share code, notes, and snippets.

@bonfil1
Forked from scodx/git patches.md
Created November 15, 2018 18:58
Show Gist options
  • Save bonfil1/9b0f287a8ba938c7815eceda049372cf to your computer and use it in GitHub Desktop.
Save bonfil1/9b0f287a8ba938c7815eceda049372cf to your computer and use it in GitHub Desktop.

Generate a patch from un-commited files:

git diff > file.patch

But sometimes it happens that part of the stuff you're doing are new files that are untracked and won't be in your git diff output. So, one way to do a patch is to stage everything for a new commit (but don't do the commit), and then:

git diff --cached > file.patch

Add the 'binary' option if you want to add binary files to the patch (e.g. mp3 files):

git diff --cached --binary > file.patch

Generate a patch between two commits

git diff commitid1 commitid2 > file.patch

Generate a patch between the HEAD and a specific commits

git diff commitid1 > file.patch

Generating a patch from excluded files

diff -u path/to/file path/to/new/file > file.patch

Generate a patch from git stash

git stash show -p > file.patch

Apply the patch:

git apply mypatch.patch

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