This is the situation:
We created a "private" repo (say our-repo) based off an existing open-source git repo (say source-repo).
We have been developing code and have around 20 merges into our repo. So, the repo moved from "State_Initial" to "State_Current".
Now, for business reasons, we want to hand-over all our development to a third party. Based on some legal issues, the only option is we give them a "single" patch file with all our changes. That is a squashed patch between "State_Initial" and "State_Current".
I looked around, and found
git format-patch -X
But, it generates "n" .patch files.
Is there a way to create a single patch file, so that if we create a repo based off "source-repo" and apply the patch, it takes us to "State_Current"?
In order to create Git patch file for a specific commit, use the “git format-patch” command with the “-1” option and the commit SHA. In order to get the commit SHA, you have to use the “git log” command and look for the corresponding commit SHA.
Patch is a text file, whose contents are similar to Git diff, but along with code, it also has metadata about commits; e.g., commit ID, date, commit message, etc. We can create a patch from commits and other people can apply them to their repository. Jerry implements the strcat function for his project.
The following command creates a single .patch
file that contains multiple commits.
git format-patch cc1dde0dd^..6de6d4b06 --stdout > foo.patch
You can then apply it like so:
git am foo.patch
Note: Be sure to use ^..
instead of ..
if you want the first commit SHA to be included.
Create a new branch named squashed
that has a single squashed commit. This branch will have the exact same contents as your normal branch but none of the history.
Look it over and if you're satisfied, use format-patch
to create a patch file.
$ git checkout -b squashed $(git commit-tree HEAD^{tree} -m 'Squashed history')
$ git format-patch --root HEAD
This is a non-destructive operation and you can switch right back to your normal development branch afterwards. You can tag
the squashed branch to save a reference to what you e-mailed them, or use branch -D
to delete it if you no longer need it.
$ git branch -D squashed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With