使新的git分支仅包含一些文件的完整历史记录 [英] make new git branch containing full history of only some files
问题描述
我处于重构的中间,最终将我从围绕它构建的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
only ,以及它们的完整提交来自当前分支的历史?
您有几个选项可以做到这一点: $ b
I'm in the middle of a refactor that will eventually separate out "the core model" from the API i've built around it.
I have the current (simplified) directory structure:
/root
|-model_core.py
|-model_configuration.py
|-model_frontend.py
|-plot_model.py
|-cool_use_for_model.py
How do I make a new branch, model-core
, that contains model_core.py
and model_configuration.py
only, as well as their full commit history from the current branch?
You have few options to do it:
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/
The main 2 optins are:
git filter-branch
git subtree split --prefix=lib -b split
As mentioned above lets explain in details each options
filter-branch will loop over each commit and then you can checkout only the given files while git subteree split
will be a better option in your case.
Explaining both of the option so you can choose which one you prefer.
Sample code:
filter-branch
# Filter the master branch to your directory and remove empty commits
git filter-branch --prune-empty --subdirectory-filter YOUR_FOLDER_NAME filter_from_branch
This will checkout all your desired files from the given folder to the current directory
subtree split
git subtree
git-subtree
-Merge
subtrees together orsplit
repository into subtrees
git subtree split -P <name-of-folder> -b <name-of-new-branch>
这篇关于使新的git分支仅包含一些文件的完整历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!