Skip to content

Instantly share code, notes, and snippets.

@clue
Last active August 29, 2015 14:01
Show Gist options
  • Save clue/4212c21860f4078a89dc to your computer and use it in GitHub Desktop.
Save clue/4212c21860f4078a89dc to your computer and use it in GitHub Desktop.
git clone https://github.com/reactphp/react source
cd source
# list all branches that should be preserved
# only version branches listed, as to skip WIP branches
git branch 0.3 origin/0.3
git branch 0.4 origin/0.4
#master is already included (default from clone)
# remove reference from origin to speed up rewriting its references
git remote remove origin
# now rewrite the whole history by moving src/React/* to src/*
# this will allow us to extract the contents in a consistent directory structure
git filter-branch --index-filter \
'git ls-files -s | sed "s/src\/React/src/" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' -- --all
# remove backup references automatically created by git-filter-branch
rm -r .git/refs/original/
# now that everything is always located in src/$COMPONENT we can easily extract its sole history
git filter-branch --subdirectory-filter src/EventLoop/ -- --all
# remove backup references automatically created by git-filter-branch
rm -r .git/refs/original/
# Done already! :)
# Final steps:
# gitg # inspect repo locally, then consider pushing:
# git push --all https://github.com/reactphp/event-loop # push all branches to target repo
# git push --tags https://github.com/reactphp/event-loop # push all tags to target repo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment