我正在进行重构,最终将把“核心模型”从我围绕它构建的 API 中分离出来。
我有当前(简化的)目录结构:
/root
|-model_core.py
|-model_configuration.py
|-model_frontend.py
|-plot_model.py
|-cool_use_for_model.py
如何创建一个新分支 model-core
,其中包含 model_core.py
和 model_configuration.py
仅,以及当前分支的完整提交历史记录?
最佳答案
您有几种选择:
http://blogs.atlassian.com/2014/04/tear-apart-repository-git-way/
https://lostechies.com/johnteague/2014/04/04/using-git-subtrees-to-split-a-repository/
主要的 2 个选项是:
git filter-branch
git subtree split --prefix=lib -b split
如上所述,让我们详细解释每个选项
filter-branch 将循环遍历每个提交,然后您可以仅 checkout 给定的文件,而 git subteree split
在您的情况下将是更好的选择。
解释这两个选项,以便您选择您喜欢的一个。
示例代码:
过滤器分支
# Filter the master branch to your directory and remove empty commits
git filter-branch --prune-empty --subdirectory-filter YOUR_FOLDER_NAME filter_from_branch
这会将给定文件夹中的所有所需文件 check out 到当前目录
子树分割
git subtree
git-subtree
-Merge
subtrees together orsplit
repository into subtrees
git subtree split -P <name-of-folder> -b <name-of-new-branch>
关于git - 创建新的 git 分支,仅包含某些文件的完整历史记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36184532/