{"id":758,"date":"2015-06-13T13:31:02","date_gmt":"2015-06-13T17:31:02","guid":{"rendered":"http:\/\/blog.fritzhardy.com\/?p=758"},"modified":"2015-06-14T11:14:01","modified_gmt":"2015-06-14T15:14:01","slug":"git-patch-export","status":"publish","type":"post","link":"https:\/\/blog.fritzhardy.com\/?p=758","title":{"rendered":"Git: Patch Export"},"content":{"rendered":"<p>Recent work has had me <a href=\"https:\/\/blog.fritzhardy.com\/?p=725\">splitting and merging git repositories<\/a> using git filter-branch to carve down a cloned repo to just the desired file(s).  An alternative is to use git format-patch to export the patch series representative of a file&#8217;s history.<\/p>\n<p>This approach is outlined perfectly here:<br \/>\n<a href=\"http:\/\/tomrobertshaw.net\/2013\/09\/migrate-file-to-a-new-git-repository-while-preserving-version-history\">http:\/\/tomrobertshaw.net\/2013\/09\/migrate-file-to-a-new-git-repository-while-preserving-version-history<\/a><\/p>\n<p>A brief example while working on my <a href=\"http:\/\/www.fritzhardy.com\/projects\/qmail-skim\">qmail-skim<\/a> project.  In this case a source repository contained a file qmail-skim.pl, and I wished to export its history for use in a new standalone repository.<\/p>\n<p>Export patches from a clone of the source repo:<\/p>\n<pre>\r\ncd \/clone\/of\/repo\r\ngit format-patch -o ~\/tmp\/patches --root scripts\/email\/qmail-skim.pl\r\n\/home\/hardyjm\/tmp\/patches\/0001-Initial-commit-of-qmail-skim.pl-the-configurable-qma.patch\r\n\/home\/hardyjm\/tmp\/patches\/0002-qmail-skim.pl.patch\r\n\/home\/hardyjm\/tmp\/patches\/0003-qmail-skim.pl.patch\r\n\/home\/hardyjm\/tmp\/patches\/0004-phishhook-snagging-implemented.patch\r\n\/home\/hardyjm\/tmp\/patches\/0005-Fixed-bug-in-phishfrom-check-properly-sanitizing-fro.patch\r\n...\r\n<\/pre>\n<p>Create a new repository:<\/p>\n<pre>\r\ncd \/somewhere\r\nmkdir qmail-skim\r\ncd qmail-skim\r\ngit init\r\nInitialized empty Git repository in \/home\/hardyjm\/tmp\/qmail-skim\/.git\r\n<\/pre>\n<p>Import the patchset:<\/p>\n<pre>\r\ngit am ~\/tmp\/patches\/*.patch\r\nApplying: Initial commit of qmail-skim.pl, the configurable qmail-queue filtering replacement.\r\nApplying: qmail-skim.pl: -fixed bug debugging...\r\nApplying: qmail-skim.pl: -phishhook snagging implemented...\r\nApplying: phishhook snagging implemented\r\nApplying: Fixed bug in phishfrom check...\r\n...\r\n<\/pre>\n<p>At the end of the process, the destination repository contains the file and its history.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recent work has had me splitting and merging git repositories using git filter-branch to carve down a cloned repo to just the desired file(s). An alternative is to use git format-patch to export the patch series representative of a file&#8217;s history. This approach is outlined perfectly here: http:\/\/tomrobertshaw.net\/2013\/09\/migrate-file-to-a-new-git-repository-while-preserving-version-history A brief example while working on my [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-758","post","type-post","status-publish","format-standard","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/blog.fritzhardy.com\/index.php?rest_route=\/wp\/v2\/posts\/758","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.fritzhardy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fritzhardy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fritzhardy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fritzhardy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=758"}],"version-history":[{"count":8,"href":"https:\/\/blog.fritzhardy.com\/index.php?rest_route=\/wp\/v2\/posts\/758\/revisions"}],"predecessor-version":[{"id":769,"href":"https:\/\/blog.fritzhardy.com\/index.php?rest_route=\/wp\/v2\/posts\/758\/revisions\/769"}],"wp:attachment":[{"href":"https:\/\/blog.fritzhardy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=758"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fritzhardy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=758"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fritzhardy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=758"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}