【问题标题】:Git moving files from one repo to another repo for historyGit 将文件从一个存储库移动到另一个存储库以获取历史记录
【发布时间】:2021-08-13 18:46:57
【问题描述】:

我需要将几个文件从一个存储库移动到另一个具有文件提交历史记录的存储库。两个 repos 的结构完全不同。

Repo 2 属于另一个团队。

回购 1 - /folder1/subfolder1/text.txt

回购 2 - 文件夹 1/test.txt

我们有办法做到这一点吗?

【问题讨论】:

标签: git github


【解决方案1】:

您可以修改How to move files from one git repo to another (not a clone), preserving history 中的答案,例如

git filter-branch --subdirectory-filter sourcedir/subdir \
        --index-filter '
                git read-tree --empty
                git ls-tree -r $GIT_COMMIT:sourcedir/subdir \
                | sed s,\\t,\\tdestdir/, \
                | git update-index --index-info
        '

并向 sed 添加您想要的任何其他选择/修改指令,例如将 "/.txt$/!d;" 放在它的前面,这样您就可以删除除 .txt 文件之外的所有内容,或者您​​想要对路径名执行的任何其他操作。

【讨论】:

    猜你喜欢
    • 2011-06-30
    • 2013-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-30
    • 1970-01-01
    相关资源
    最近更新 更多