Extract branch to a new repo using git-format-patch
I know this should probably be done using git-filter-branch, but with format-patch, I don’t need to learn anything new. More importantly, filter-branch would give me more to forget
Given a git repo with a branch ‘find-ls’ with history like this:
1 2 3 4 5 6 7 8 | * 10c757c (origin/master, master) handle errors better | * 073892b (HEAD, find-ls) don't allow new(dist => ...) | * 2684370 give up on Test::Class | * fd7f30c constructor_should_have_valid_cpan | * 67c3d4d initial commit |/ * 9758db3 add deploy-prefs.pl * 2c4d459 monitor.pl: show startup message if log shrinks |
Create a bunch of patches, like so:
1 2 | git checkout find - ls git format -patch 9758db3 # where find-ls branched |
If you need to have your new repo have a different structure, you might need to hack the patches. I just used:
1 | perl -pi -E 's|LEADING-DIR/||g' *.patch |
Then you can apply the patches:
1 2 3 | mv 0*.patch where /I/want/my/new/repo cd where /I/want/my/new/repo git am *.patch |
Move this (or re-title) to ‘git tips’
briang
September 15, 2011