如何使用git-filter-repo将一个仓库作为子目录合并到另一个仓库 [英] How to use git-filter-repo to merge one repo as subdirectory into another
本文介绍了如何使用git-filter-repo将一个仓库作为子目录合并到另一个仓库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用此 gist .仅添加相关的代码段:
While trying to use git filter-branch
to merge repos using this gist. Adding just the relevant snippet in question:
git filter-branch -f --prune-empty --tree-filter '
mkdir -p "${REPO_NAME}_tmp"
git ls-tree --name-only $GIT_COMMIT | xargs -I{} mv {} "${REPO_NAME}_tmp"
mv "${REPO_NAME}_tmp" "$REPO_NAME"
'
我从git收到警告,内容如下:
I got a warning from git stating the following:
WARNING: git-filter-branch has a glut of gotchas generating mangled history
rewrites. Hit Ctrl-C before proceeding to abort, then use an
alternative filtering tool such as 'git filter-repo'
(https://github.com/newren/git-filter-repo/) instead. See the
filter-branch manual page for more details; to squelch this warning,
set FILTER_BRANCH_SQUELCH_WARNING=1.
So, I took a look at git filter-repo
, the description states the following:
重组文件布局(例如,将所有文件移动到子目录中,以准备与另一个仓库合并...
restructuring the file layout (such as moving all files into a subdirectory in preparation for merging with another repo, ...
这表明可以使用 git filter-repo
解决此问题,但是即使在检查了文档并给出
This showed that this issue can be resolved with git filter-repo
, but even after checking the documentation and given examples I could not find a way to achieve this. Can someone please help me with the same.
推荐答案
在脚本中替换 filter-branch
命令
git filter-branch -f --prune-empty --tree-filter '
mkdir -p "${REPO_NAME}_tmp"
git ls-tree --name-only $GIT_COMMIT | xargs -I{} mv {} "${REPO_NAME}_tmp"
mv "${REPO_NAME}_tmp" "$REPO_NAME"
'
与此
git filter-repo --to-subdirectory-filter "$REPO_NAME"
查看全文