问题描述
使用此 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.
所以,我看了 git filter-repo
,说明指出以下内容:
So, I took a look at git filter-repo
, the description states the following:
这表明可以使用 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"
请参见路径快捷方式部分此处
将项目根目录视为< directory>
等同于使用-path-rename:< directory>/
这篇关于如何使用git-filter-repo将一个仓库作为子目录合并到另一个仓库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!