这个问题与:
- 将许多子目录分离到新的单独的 git 存储库中
- Git 子树和多个目录
我不想分离单个子目录,而是想分离几个子目录。例如,这是我的文件夹结构:
/app1
/file1
/file2
/folder1
/folder2
/app2
/file3
/file4
/folder3
/folder4
/test
/file5
/file6
/folder5
/folder6
/README.md
/new_file
我想要这个:
/app1
/file1
/file2
/folder1
/folder2
/app2
/file3
/file4
/folder3
/folder4
我已经尝试过以下替代方案,但到目前为止没有一个有效:
git filter-branch --index-filter 'git rm --cached -qr -- . && git reset -q $GIT_COMMIT -- /app1/* app2/*' --prune-empty -- --all
Error:
pathspec '.' did not match any files
第二次尝试:
git filter-branch --tree-filter "mkdir samples; mv app1 app2 samples/" HEAD
Error:
rename app1 to samples/app1: No such file or directory
Same error for the second sub-directory
有任何想法吗?
在使用树过滤器的情况下,您将评估每个提交的脚本,即使是 app1 和 app2 可能不存在的提交,这可以通过守卫和不会失败的替代命令来解决。
git filter-branch --tree-filter "mkdir samples && test -d app1 && mv app1 samples/|| test -d app2 && mv app2 samples/ || echo 'nothing to do'" HEAD
然后将示例设置为根目录,这会将 app1 和 app2 移动到项目的根目录。
git filter-branch -f --subdirectory-filter samples -- --all
我建议您先进行备份!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)