如何使用 git-filter-repo 将一个 repo 作为子目录合并到另一个

Aag*_*aaz 9 git github git-filter-branch git-filter-repo

在尝试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"
    '
Run Code Online (Sandbox Code Playgroud)

我收到来自 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.
Run Code Online (Sandbox Code Playgroud)

所以,我看了看git filter-repo描述如下:

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

这表明可以使用 解决此问题git filter-repo,但即使在检查文档并给出示例后,我也找不到实现此目的的方法。有人可以帮我做同样的事情。

Sau*_*ari 8

替换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"
    '
Run Code Online (Sandbox Code Playgroud)

有了这个

git filter-repo --to-subdirectory-filter "$REPO_NAME"
Run Code Online (Sandbox Code Playgroud)

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

--到子目录过滤器<directory>

将项目根视为位于<directory>

相当于使用--path-rename :<directory>/