Quick way to create a patch with git from two different branches
Intro#
In order to get a patch from the diff between master
and foo
branches one could use the following:
Generate the Patch#
git diff --no-color --binary master foo > /tmp/patch
Apply changes#
To later apply the patch:
git apply /tmp/patch
Changes within the same branch#
If you don’t have dedicated branches with the changes and all are on the same branch you can just execute
git diff --no-color --binary > /tmp/patch
NOTE:
--no-color
ensures the diff is valid to apply if you have automatic coloring on,--binary
ensures binary files are handled correctly as well.