Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git commit patches

Tags:

git

git-diff

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.

like image 449
Chris Smith Avatar asked Feb 20 '23 04:02

Chris Smith


2 Answers

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
like image 142
user4815162342 Avatar answered Feb 28 '23 14:02

user4815162342


You can select any range you want with format-patch

git format-patch --stdout R1..HEAD > output.patch
like image 41
Eduardo Avatar answered Feb 28 '23 14:02

Eduardo