Skip to content

Instantly share code, notes, and snippets.

@Iristyle
Created January 26, 2018 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Iristyle/7cca585a13253daa933ab656bc33442f to your computer and use it in GitHub Desktop.
Save Iristyle/7cca585a13253daa933ab656bc33442f to your computer and use it in GitHub Desktop.
Demonstrate how to use Git to create a new repo with specific files from a current repo

I tried to initially do this using the perl based cj-git-filter-branch tool from https://github.com/pflanze/chj-bin (which required ensuring Perl was viable and a few CPAN packages were installed) with a CLI invocation like:

~/source/chj/chj-bin/cj-git-filter-branch --remove-all-but-those-in ../keepers.txt -f

And a keepers.txt like:

acceptance/tests/resource/scheduled_task/should_create.rb
acceptance/tests/resource/scheduled_task/should_destroy.rb
acceptance/tests/resource/scheduled_task/should_modify.rb
acceptance/tests/resource/scheduled_task/should_query.rb
lib/puppet/provider/scheduled_task/win32_taskscheduler.rb
lib/puppet/type/scheduled_task.rb
lib/puppet/util/windows/taskscheduler.rb
spec/unit/provider/scheduled_task/win32_taskscheduler_spec.rb
spec/unit/type/scheduled_task_spec.rb

But then ended up doing some additional massaging like

git filter-branch -f --prune-empty --parent-filter ~/source/puppetlabs-scheduled_task/puppet-code/rewrite_parent.rb
#!/usr/bin/ruby
old_parents = gets.chomp.gsub('-p ', ' ')

if old_parents.empty? then
  new_parents = []
else
  new_parents = `git show-branch --independent #{old_parents}`.split
end

puts new_parents.map{|p| '-p ' + p}.join(' ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment