如何使用 git-filter-repo 将一个 repo 作为子目录合并到另一个
How to use git-filter-repo to merge one repo as subdirectory into another
尝试使用 git filter-branch
合并存储库时使用此 gist。仅添加有问题的相关代码段:
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 的警告,内容如下:
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
,description 说明如下:
restructuring the file layout (such as moving all files into a subdirectory in preparation for merging with another repo, ...
这表明可以使用 git filter-repo
解决此问题,但即使在查看文档并给出 examples 后,我也找不到实现此目的的方法。有人可以帮我做同样的事情吗?
这看起来像是路径重命名,作为 path-based filters:
的一部分
cd $REPO_DIR_TMP
git filter-repo --path-rename /:${REPO_NAME}_tmp/
这将重写子文件夹中第二个回购的历史记录(在第二个回购中)
然后你可以将它添加为第一个 repo 的远程,获取并合并,就像在你的 gitst 中一样。
替换脚本中的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"
参见路径快捷方式部分here
--to-subdirectory-filter <directory>
Treat the project root as instead being under <directory>
Equivalent to using --path-rename :<directory>/
尝试使用 git filter-branch
合并存储库时使用此 gist。仅添加有问题的相关代码段:
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 的警告,内容如下:
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
,description 说明如下:
restructuring the file layout (such as moving all files into a subdirectory in preparation for merging with another repo, ...
这表明可以使用 git filter-repo
解决此问题,但即使在查看文档并给出 examples 后,我也找不到实现此目的的方法。有人可以帮我做同样的事情吗?
这看起来像是路径重命名,作为 path-based filters:
的一部分cd $REPO_DIR_TMP
git filter-repo --path-rename /:${REPO_NAME}_tmp/
这将重写子文件夹中第二个回购的历史记录(在第二个回购中)
然后你可以将它添加为第一个 repo 的远程,获取并合并,就像在你的 gitst 中一样。
替换脚本中的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"
参见路径快捷方式部分here
--to-subdirectory-filter
<directory>
Treat the project root as instead being under
<directory>
Equivalent to using
--path-rename :<directory>/