Skip to content

Instantly share code, notes, and snippets.

@chadly
Last active August 29, 2015 14:05
Show Gist options
  • Save chadly/a88cc9455a6f99c58bd8 to your computer and use it in GitHub Desktop.
Save chadly/a88cc9455a6f99c58bd8 to your computer and use it in GitHub Desktop.
Split project out from another repo with a folder rename in the middle
#!/bin/bash
#http://stackoverflow.com/a/6638058/316108
git branch rename 65a6c070f80b3b3e071fed8360c1b589a2b64018
git branch pre-rename rename~
## First filter all commits up to rename, but not rename itself
git filter-branch --prune-empty --subdirectory-filter CivicSource/CivicSource.Util/CivicSource.Migrator pre-rename
## Add a graft, so our rename rev comes after the processed pre-rename revs
echo `git rev-parse rename` `git rev-parse pre-rename` >> .git/info/grafts
## The first filter-branch left a refs backup directory. Move it away so the next filter-branch doesn't complain
mv .git/refs/original .git/refs/original0
## Now filter the rest
git filter-branch --prune-empty --subdirectory-filter src/CivicSource/CivicSource.Util/CivicSource.Migrator master ^pre-rename
## The graft is now baked into the branch, so we don't need it anymore
rm .git/info/grafts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment