git子树添加:更改前缀保留本地提交

时间:2014-02-11 13:19:23

标签: git git-subtree

有一种简单的方法可以移动使用以下cmd

添加的子树
git subtree add --prefix=<prefix> <repository> <commit>

换句话说,是否可以将前缀从dir1更改为dir2

git subtree: possible to change subtree branch/path in a forked repository?的答案建议删除子树然后再添加。

它对我不起作用,因为我需要保留本地提交,还有另一种方法吗?

1 个答案:

答案 0 :(得分:5)

一种替代方法是从您当前的提交中拆分,包括您要保留的本地提交:

git subtree split --prefix=dir1 HEAD

# Create a branch with the printed commit just to use it later
git branch split_dir_1 <split_commit>

然后执行question you mentioned中描述的内容,删除子目录并重新添加子树。

git rm dir1
git commit
git subtree add --prefix=dir2 . split_commit

请记住,通过执行此操作,您仍然可以在创建并删除并重新添加第一个子树时查看存储库历史记录。