Is there a way to export a sequence of commits into a patch from Git. Say I need to export the last 5 commits from a repository and import them into another repository. How would I go about doing that?
Help with this would be appreciated.
git format-patch
is designed for that purpose:
git format-patch --stdout HEAD~5 > ~/patches
The output is a readable BSD-mailbox-style file that contains patches along with some metadata such as the commit messages. To import the patches into the other repository, use git am
:
git am < ~/patches
You can select any range you want with format-patch
git format-patch --stdout R1..HEAD > output.patch
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