Git: Move files from one repo to another with history (2021)
a year ago
- #RepositoryManagement
- #Git
- #VersionControl
- 在Git仓库之间导出带有历史记录的文件可能很复杂,但使用`git filter-repo`可以简化这一过程。
- 由于历史重写问题和Git CLI的警告,不再推荐使用`git filter-branch`。
- 打补丁是另一种方法,但与`filter-repo`相比可能更复杂且不够无缝。
- 需要单独安装`git filter-repo`,因为它默认不包含在Git CLI中。
- `filter-repo`的关键选项:`--path`用于包含文件/文件夹,`--invert-paths`用于排除它们。
- 移动文件及其历史的步骤:清理源仓库,在目标仓库中添加源仓库为远程仓库,获取并合并更改,然后清理。
- 首先在本地分支执行清理操作,以避免影响原始仓库。
- 使用`git remote add`、`git fetch`和`git merge --allow-unrelated-histories`来集成更改。
- 清理工作包括在合并后移除远程源和分支。