将许多子目录拆分成一个新的单独的Git存储库 [英] Splitting many subdirectories into a new, separate Git repository
问题描述
这个问题涉及到:
不是分离一个子目录,而是分离一对。例如,以下是我的文件夹结构:
/ 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
错误:
pathspec'。'与任何文件不匹配
第二次尝试:
git filter-branch --tree-filtermkdir samples; mv app1 app2 samples /HEAD
错误:
将app1重命名为samples / app1:没有这样的文件或目录
第二个子目录相同的错误
任何想法?
$在使用树型过滤器的情况下,您将评估每次提交的脚本,甚至可以提交app1和app2可能不存在的地方,这可以解决由警卫和另一个不会失败的命令构成。 git filter-branch --tree-filtermkdir samples& & test -d app1& mv app1 samples / || test -d app2& mv app2 samples / || echo'nothing to do'HEAD
然后制作根目录的样本,这将是l将app1和app2移动到项目的根目录下。
$ g $ filter $ git filter-branch -f --subdirectory-filter samples - - all
我建议您先进行备份!
This question is related to:
Instead of detaching a single subdirectory, I want to detach a couple. For example, here is my folder structure:
/app1
/file1
/file2
/folder1
/folder2
/app2
/file3
/file4
/folder3
/folder4
/test
/file5
/file6
/folder5
/folder6
/README.md
/new_file
And I would like this instead:
/app1
/file1
/file2
/folder1
/folder2
/app2
/file3
/file4
/folder3
/folder4
I have tried the below alternatives, and none have worked so far:
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
Second Try:
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
Any ideas?
In the case with tree-filter you will evaluate the script for each commit, even commits where app1 and app2 may not exist, this can be solved by a guard and an alternative command that does not fail.
git filter-branch --tree-filter "mkdir samples && test -d app1 && mv app1 samples/|| test -d app2 && mv app2 samples/ || echo 'nothing to do'" HEAD
Then making samples the root directory, this will move app1 and app2 to the root of the project.
git filter-branch -f --subdirectory-filter samples -- --all
I recommend that you do a backup first!
这篇关于将许多子目录拆分成一个新的单独的Git存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!