This is a read-only version of imagej.net, available during the transition to a new site.
Please direct any questions or issues to this Image.sc Forum thread.
Thank you for your patience as we improve the website!
Please direct any questions or issues to this Image.sc Forum thread.
Thank you for your patience as we improve the website!
How to extract a subproject
Git Tutorials | |
---|---|
Git for dummies | |
Git in Eclipse (EGit)
| |
Git mini howto | |
Git workshop | |
Git Conflicts | |
Git topic branches | |
Git Notes | |
Git reflogs | |
Git submodule tutorial | |
Pinpoint regressions with Git | |
How to publish a Git repository | |
How to extract a subproject |
Sometimes, a piece of functionality is developed as part of one project, but grows so much as to warrant becoming its own, separate project.
This tutorial describes how to split part of a Git repository into its own dedicated Git repository, preserving only the history relevant to the subproject being extracted.
Contents
Extract the revision history
- Use Git's filter-branch feature to extract the Git history of only the subproject:
git filter-branch -f --prune-empty --subdirectory-filter <subdir>
Where<subdir>
is the folder containing the subproject's source code.
Update the Maven build
Assuming you are using Maven to build the subproject:
- Add an <scm> section to the pom.xml to reflect the new remote repository's URL (see example):
vi pom.xml git commit -m 'Add SCM location' pom.xml
- Replace the old <parent> with a new one, such as pom-scijava, pom-imagej or pom-fiji (see example)—or remove the <parent> altogether.
- Add a <developers> section to the pom.xml to indicate the project developers (see example). You can also add <contributors> if desired and relevant.
- Make sure the project still builds:
mvn clean package
- Add (or adjust) the .gitignore file (see example).
Push the changes
- Make sure that all your changes look good:
git status git diff
This is good advice in general: checkgit status
andgit diff
every time before you commit, to prevent making a fool out of yourself. - Commit everything, mentioning the commit of the parent project from which history was rewritten (see example):
git add . && git commit -s
- Create a new repository somewhere for the new project—we recommend GitHub.
- Connect your repository with the remote one:
git remote set-url origin git@github.com:my-org/my-new-project
Where git@github.com:my-org/my-new-project is the remote URL for the new project's dedicated repository. - Push the resultant history to the project's new repository:
git push -u origin master
Change any online resources
- Edit the relevant web page(s) to reflect the new Git repository location
- Update any other known links to the project