繁体   English   中英

如何使用 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描述如下:

重组文件布局(例如将所有文件移动到子目录中以准备与另一个 repo 合并,...

这表明这个问题可以通过git filter-repo解决,但即使在检查了文档和给出的示例之后,我也找不到实现此目的的方法。 有人可以帮助我吗?

替换脚本中的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"

请参阅此处的路径快捷方式部分

--to-subdirectory-filter <directory>

将项目根目录视为位于<directory>

等效于使用--path-rename:<directory>/

这看起来像一个路径重命名,作为基于路径的过滤器的一部分:

cd  $REPO_DIR_TMP
git filter-repo  --path-rename /:${REPO_NAME}_tmp/

这将重写子文件夹中第二个 repo 的历史记录(在第二个 repo 内)

然后你可以将它添加为第一个 repo 的远程,获取和合并,就像在你的 gitst 中一样。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM