是否有一种简单的方法来移动使用以下cmd添加的子树
git subtree add --prefix=<prefix> <repository> <commit>
Run Code Online (Sandbox Code Playgroud)
换句话说,是否可以将前缀更改dir1为dir2.
git子树的答案:可以在分叉存储库中更改子树分支/路径吗?建议删除子树然后添加回来.
它对我不起作用,因为我需要保留本地提交,还有另外一种方法吗?
另一种方法是从当前提交中拆分,包括要保留的本地提交:
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>
Run Code Online (Sandbox Code Playgroud)
然后执行您提到的问题中描述的内容,删除子目录并重新添加子树.
git rm dir1
git commit
git subtree add --prefix=dir2 . split_commit
Run Code Online (Sandbox Code Playgroud)
请记住,通过执行此操作,您仍然可以在存储库历史记录中查看第一个子树的创建,删除和重新添加的时间.