Skip to content

Instantly share code, notes, and snippets.

@jtsternberg
Created February 3, 2015 16:57
Show Gist options
  • Select an option

  • Save jtsternberg/49f118baa999ed27a68d to your computer and use it in GitHub Desktop.

Select an option

Save jtsternberg/49f118baa999ed27a68d to your computer and use it in GitHub Desktop.
Extract a plugin and its commit history from a larger repo (wp-content)
#
# Cutting the rss-post-aggregate plugin and its history out of a (wp-content) repo
#
# clone wp-content repo to a folder named for the plugin
$ git clone [email protected]:/your-organization/your-wp-content-repo.git rss-post-aggregator
# Remove original origin remote (won't be needed)
$ git remote rm origin
# Remove all folders that are NOT the plugins folder
$ git filter-branch --force --index-filter 'git rm -r --cached --ignore-unmatch mu-plugins languages themes Gruntfile.js grunt.mp3 package.json' --prune-empty --tag-name-filter cat -- --all
# Remove all plugins from the repo and history that are NOT our plugin of choice, rss-post-aggregate (list of plugins removed modified for brevity)
$ git filter-branch --force --index-filter 'git rm -r --cached --ignore-unmatch plugins/wp-large-options plugins/wds-redirects plugins/wds-mu-plugins plugins/remove-blog-slug plugins/public-post-preview plugins/posts-to-posts plugins/cmb2' --prune-empty --tag-name-filter cat -- --all
# Move plugin contents up to the root of repo
$ git mv plugins/rss-post-aggregate/* .
# Commit changes
$ git c -am 'move plugin files to root'
# Git rebase from very first commit.. squash all commits that contain changes that are inapplicable to your plugin http://davidwalsh.name/squash-commits-git
$ git rebase -i 71b5a37
# Remove the now-empty plugins folder
$ rm -rf plugins
# Move back out, and backup the repo before doing any more major history rewrites
$ cd .. | cp -r rss-post-aggregator rss-post-aggregator-backup
# Remove folders found in the git history that are NOT our plugin (or applicable to our plugin) (again, modified for brevity)
$ git filter-branch --force --index-filter 'git rm -r --cached --ignore-unmatch plugins/debug-bar plugins/debug-bar-console plugins/query-monitor plugins/theme-check .gitignore .gitmodules' --prune-empty --tag-name-filter cat -- --all
# At this point, your repo should be clean enough to push to a new remote
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment