我知道编辑这个网站吗?

如何提取子项目

有时,一项功能是作为一个项目的一部分开发的,但它的发展速度如此之快,以至于有必要成为它自己的、独立的项目。

本教程介绍如何将 Git 存储库的一部分拆分为自己的专用 Git 存储库,仅保留与正在提取的子项目相关的历史记录。

提取修订历史记录

  1. 使用Git的filter-branch功能仅提取子项目的Git历史记录:
     git filter-branch -f --prune-empty --subdirectory-filter <subdir>
    

    Where <subdir> is the folder containing the subproject’s source code.

    更新 Maven 构建

假设您使用 Maven 来构建子项目:

  1. <scm> 部分添加到 pom.xml 以反映新远程存储库的 URL(请参阅example):
     vi pom.xml
     git commit -m 'Add SCM location' pom.xml
    
  2. 将旧的 <parent> 替换为新的,例如 pom-scijavapom-imagejpom-fiji(参见 example),或者完全删除 <parent>

  3. pom.xml 中添加 <developers> 部分以指示项目开发人员(参见example)。如果需要且相关,您还可以添加 <contributors>

  4. 确保项目仍在构建:
     mvn clean package
    
  5. 添加(或调整).gitignore 文件(请参阅example)。

推送更改

  1. 确保所有更改看起来都不错:
     git status
     git diff
    

    This is good advice in general: check git status and git diff every time before you commit, to prevent making a fool out of yourself.

  2. 提交所有内容,提及重写历史的父项目的提交(参见example):
     git add . && git commit -s
    
  3. 在某处为新项目创建一个新存储库——我们建议GitHub

  4. 将您的存储库与远程存储库连接:
     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.

  5. 将生成的历史记录推送到项目的新存储库:
     git push -u origin main
    

    更改任何在线资源

  6. 编辑相关网页以反映新的 Git 存储库位置
  7. 更新该项目的任何其他已知链接