Last active
July 23, 2017 17:56
-
-
Save jbrains/981912ca90eefe49bd03edd52111f681 to your computer and use it in GitHub Desktop.
Extract subproject from git repository by grafting commits onto the corresponding files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CONTRACT | |
# SOURCE_SUBPRPOJECT_ROOT points to the "same" directory tree | |
# as TARGET_PROJECT_ROOT. We're extracting the directory tree | |
# at SOURCE_SUBPROJECT_ROOT into TARGET_PROJECT_ROOT. | |
# | |
# There must be a single, linear history in the SOURCE repository. | |
# Graft the current commit into the target | |
pushd "$SOURCE_SUBPROJECT_ROOT" | |
commit_comment="$(git log -1 --pretty=%B)" | |
rsync $RSYNC_OPTIONS --delete -aiP "$SOURCE_SUBPROJECT_ROOT/" "$TARGET_PROJECT_ROOT" | |
pushd "$TARGET_PROJECT_ROOT" | |
git add -A | |
git commit --allow-empty -m "${commit_comment}" | |
popd | |
# Decide what to do next | |
next_commit_sha1="$(git log --reverse --ancestry-path HEAD..master --pretty=%H | head -n 1)" | |
if [ -n "${next_commit_sha1}" ]; | |
then | |
git checkout ${next_commit_sha1} | |
echo "Keep going." | |
else | |
echo "Done!" | |
fi | |
popd |
so what you might want is this git push ../tmp $(git subtree split --prefix=src):refs/heads/new_branch
where ../tmp
is a new git repo and new_branch
is the branch you want to create with the subtree in src
ah, there was a command for that :P git subtree push --prefix=src ../tmp newer_branch
doeas (i think) the same as the one above.
Excellent! I'll have to try it to see whether it does what I expected. I hope I remember that in case there is a next time. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One more ting though, how does the target repo look like? Is it empty or does it already have some history?