0 votes
1 view
in Devops and Agile by (14.8k points)
edited by

Say I have uncommitted changes in my working directory. How can I make a patch from those without having to create a commit?

2 Answers

0 votes
by (20.5k points)

For unstaged changes use the following command:

$ git diff 

For staged changes use the following command: 

$ git diff --cached 

0 votes
by (42.1k points)

If you haven't yet committed the changes, then:

git diff > mypatch.patch

But sometimes it happens that part of the stuff you're doing is 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 (git add each file, or just git add .) but don't do the commit, and then:

git diff --cached > mypatch.patch

Add the 'binary' option if you want to add binary files to the patch (e.g. mp3 files)(Binary files contain data stored as a series of bits (binary values of 1s and 0s), the bits in binary files represent custom data, binary files may contain both textual and custom binary data.):

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

You can later apply the patch:

git apply mypatch.patch

Note: You can also use --staged as a synonym of --cached.

...