How I solve this problem (since I hate to throw away code) is to use:
git format-patch -1 {commit}
to generate a patch file. (You can use -2
or higher numbers if you want more than 1 commit to be converted to a patch... this will create several patch files).
Then I commit the patch file to my own personal "misc" repo, which contains random useful things like notes, patch files and data samples. This doesn't affect anyone else and also reduces the risk it will be lost by someone deleting my remote branch on the code repo.
I can "apply" this patch file at any time with:
git am --reject < {patch-file}
The am
command applies the patch and the --reject
allows it to create "reject" files in case the patch can't be applied cleanly. This allows the command to partially merge what it can instead of completely failing, and the "reject" files can then be used to help you manually make the changes that failed to merge.
The result of the git am
is to recreate the commit that produced the patch file. If you want to apply several patch files, you must be careful to apply them in the original order.
(I got this idea from contributing to the git
project, because that project does not use pull requests, because Linus Torvalds hates them. Instead, it uses patch files sent to an email listserv, which can then be reviewed by fellow contributors)