{"thread":{"id":"14527","subject":"copy selected history between repostories","startedAt":"2008-07-18T16:58:49Z","lastAt":"2008-07-19T01:21:07Z","messageCount":5,"participants":["luisgutz","Avery Pennarun","Nick Andrew","Johannes Schindelin","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"83890","messageId":"18533605.post@talk.nabble.com","threadId":"14527","inReplyTo":null,"subject":"copy selected history between repostories","fromName":"luisgutz","fromEmail":"luis@xmos.com","sentAt":"2008-07-18T16:58:49Z","receivedAt":"2008-07-18T16:58:49Z","isPatch":false,"sender":{"key":"luis@xmos.com","avatar":null},"body":"\nHi All,\n\nThis is something I'm not sure how to do with git, or even if it is possible\nin git; and because google has not been my friend this time, I though I\nwould ask here.\n\nI have 2 repositories: repoA and repoB.\n\nrepoB is massive. lots of history and files. But it has a set of files\ninside a particular dir with 40-60 files that I just realized are better in\nrepoA.\n\nIs there any way to import that directory into repoA with all it's history,\nbut NOT the history from the other commits?\nAnother way of putting is this: can I make git forget the history of all\nother commits but those from this directory?\n\n\n-- \nView this message in context: http://www.nabble.com/copy-selected-history-between-repostories-tp18533605p18533605.html\nSent from the git mailing list archive at Nabble.com.\n"},{"id":"83895","messageId":"32541b130807181012o3b56c413g31667baca1732b01@mail.gmail.com","threadId":"14527","inReplyTo":"18533605.post@talk.nabble.com","subject":"Re: copy selected history between repostories","fromName":"Avery Pennarun","fromEmail":"apenwarr@gmail.com","sentAt":"2008-07-18T17:12:30Z","receivedAt":"2008-07-18T17:12:30Z","isPatch":false,"sender":{"key":"apenwarr@gmail.com","avatar":"https://avatars.githubusercontent.com/u/20592?v=4"},"body":"On 7/18/08, luisgutz <luis@xmos.com> wrote:\n>  Is there any way to import that directory into repoA with all it's history,\n>  but NOT the history from the other commits?\n>  Another way of putting is this: can I make git forget the history of all\n>  other commits but those from this directory?\n\nTry cloning the repository, then running git-filter-branch with the\n--subdirectory-filter option.  It works quite nicely.\n\nHave fun,\n\nAvery\n"},{"id":"83928","messageId":"20080719010122.GA12047@mail.local.tull.net","threadId":"14527","inReplyTo":"18533605.post@talk.nabble.com","subject":"Re: copy selected history between repostories","fromName":"Nick Andrew","fromEmail":"nick@nick-andrew.net","sentAt":"2008-07-19T01:01:22Z","receivedAt":"2008-07-19T01:01:22Z","isPatch":false,"sender":{"key":"nick@nick-andrew.net","avatar":"https://gravatar.com/avatar/85f25a67ca6eaa4016ed374f6d07f3cd853c886aeb7e1507eb7dbc47b00082fe?d=mp&s=160"},"body":"On Fri, Jul 18, 2008 at 09:58:49AM -0700, luisgutz wrote:\n> Is there any way to import that directory into repoA with all it's history,\n> but NOT the history from the other commits?\n> Another way of putting is this: can I make git forget the history of all\n> other commits but those from this directory?\n\nI couldn't figure out git-filter-branch, so I did the following,\nwhich worked for me:\n\nFirst, export commits as patches in mbox format:\n\n\tgit log -p --first-parent --reverse --pretty=email $* > mbox\n\nSecond, run the mbox file through a filter which selectively\nrenames files (since almost always I want the files in a different\ndirectory in the new repository):\n\n\tmyfilter scripts=bin perllib=lib < mbox > mbox2\n\nFinally, import into new repo:\n\n\tgit-am mbox2\n\nIt's a bit slow on the import step but it meets my needs at this time.\n\nNick.\n\nFilter script follows, for what it's worth ...\n\n\n#!/usr/bin/perl\n#\t@(#) git-filter-rename.pl\n#\n#\tRead an mbox file containing patches on standard input,\n#\tmodify the filenames within according to a list of substitutions\n#\tsupplied on the command line, and write the modified mbox file\n#\tto standard output.\n\nmy @subs;\n\nforeach (@ARGV) {\n\tif (/(.*)=(.*)/) {\n\t\tmy $len = length($1);\n\t\tpush(@subs, [ $1, $2, $len ]);\n\t} else {\n\t\tprint STDERR \"Unknown arg: $_\\n\";\n\t}\n}\n\nwhile (<STDIN>) {\n\tchomp;\n\tmy $line = $_;\n\n\tif ($line =~ /^(---|\\+\\+\\+) ([ab]\\/)(.+)$/) {\n\t\tmy $line_1 = $1;\n\t\tmy $line_2 = $2;\n\t\tmy $line_3 = $3;\n\n\t\tsubFilename($line_3);\n\n\t\tprint \"$line_1 $line_2$line_3\\n\";\n\t\tnext;\n\t}\n\n\tif ($line =~ /^diff --git ([ab]\\/)(\\S+) ([ab]\\/)(\\S+)/) {\n\t\tmy ($line_1, $line_2, $line_3, $line_4) = ($1, $2, $3, $4);\n\t\tsubFilename($line_2);\n\t\tsubFilename($line_4);\n\t\tprint \"diff --git $line_1$line_2 $line_3$line_4\\n\";\n\t\tnext;\n\t}\n\n\tprint $line, \"\\n\";\n}\n\nexit(0);\n\n# ------------------------------------------------------------------------\n# Substitute a filename in-place (modifies argument)\n# ------------------------------------------------------------------------\n\nsub subFilename {\n\n\tforeach my $lr (@subs) {\n\t\tmy ($lhs, $rhs, $len) = @$lr;\n\t\tif (substr($_[0], 0, $len) eq $lhs) {\n\t\t\tprint STDERR \"Match on $lhs, $_[0]\\n\";\n\t\t\tsubstr($_[0], 0, $len) = $rhs;\n\t\t\tlast;\n\t\t}\n\t}\n}\n"},{"id":"83929","messageId":"alpine.DEB.1.00.0807190311440.3064@eeepc-johanness","threadId":"14527","inReplyTo":"20080719010122.GA12047@mail.local.tull.net","subject":"Re: copy selected history between repostories","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-07-19T01:12:55Z","receivedAt":"2008-07-19T01:12:55Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 19 Jul 2008, Nick Andrew wrote:\n\n> \tmyfilter scripts=bin perllib=lib < mbox > mbox2\n\nNote that if your repository only contains text files, \"git fast-export | \nmy-filter | git fast-import --force\" would have worked faster, probably.\n\nBut I am glad you figured out how to do what you wanted to do.\n\nCiao,\nDscho\n"},{"id":"83931","messageId":"20080719012107.GA14068@sigill.intra.peff.net","threadId":"14527","inReplyTo":"20080719010122.GA12047@mail.local.tull.net","subject":"Re: copy selected history between repostories","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-07-19T01:21:07Z","receivedAt":"2008-07-19T01:21:07Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Jul 19, 2008 at 11:01:22AM +1000, Nick Andrew wrote:\n\n> I couldn't figure out git-filter-branch, so I did the following,\n> which worked for me:\n> \n> First, export commits as patches in mbox format:\n> \n> \tgit log -p --first-parent --reverse --pretty=email $* > mbox\n> [...]\n> \n> Finally, import into new repo:\n> \n> \tgit-am mbox2\n\nNote that this will lose any interesting history topology you had, like\nbranching and merging (and it may have trouble applying all patches in\nthat case, too). But if your history was a straight line, it should\nproduce equivalent results.\n\n-Peff\n"}]}