我正在从现有的源树中拆分库,以便可以单独维护库。
您如何提取一个文件的所有提交并将其导入另一棵树,但没有所有的.git/对象从原始树中杂乱无章?
我当时在想这样的事情:
cd /new/tree
git init
cd /original/tree
git show --reverse 815f0f..HEAD -- lib/PDL/Opt/Simplex/Simple.pm | \
(cd /new/tree ; git am)
但是它会出现错误并且不会导入。
我还想到了仅分支,删除所有内容,然后将修剪的分支取得到新树中---但(我认为)会导入所有其他树的提交数据中的所有。 。
是否有一种“正确的”方式干净地做到这一点?
I'm splitting out a library from an existing source tree so the library can be maintained separately.
How do you extract all the commits for one file and import them into another tree, but without all the .git/objects clutter from the original tree?
I was thinking something like this:
cd /new/tree
git init
cd /original/tree
git show --reverse 815f0f..HEAD -- lib/PDL/Opt/Simplex/Simple.pm | \
(cd /new/tree ; git am)
but it gives errors and won't import.
I also thought of just branching, deleting everything, and then fetching the pruned branch into a new tree---but (I think) that would import all the other tree's commit data in .git/objects that would be orphaned in the new tree.
Is there a "proper" way to do this cleanly?
发布评论
评论(2)
复制从 https://github.com/ pdlporters/devops/blob/master/notes.md#how-to-split-History :
如何拆分历史记录
确保已安装
git-subtree
已安装并有效(如果不是,请从和place
+X
在/usr/usr/local/libexec/git-core/git-subtree
)Copied from https://github.com/PDLPorters/devops/blob/master/NOTES.md#how-to-split-history:
How to split history
Make sure
git-subtree
is installed and works (if not, get fromhttps://github.com/git/git/blob/master/contrib/subtree/git-subtree.sh and place
with
+x
in/usr/local/libexec/git-core/git-subtree
)这起作用了。如果您有更好的方法,我也愿意接受其他答案:
This worked. I'm open to other answers, too, if you have a better way: