首页 > 解决方案 > 如何使用 rebase 从 repo 中提取而不获得较旧的提交

问题描述

我有一个包含近 900 次提交的父仓库,我正在从中创建子仓库。我已经尝试了我所知道的几乎所有可能的变体,包括使用父 repo 作为模板

我想要实现的与 repo 模板提供的类似。我想从单一提交的新回购开始。当我从父 repo 中提取时出现问题(它在子 repo 的提交历史中带来了父 repo 的所有 900 次提交)。我还尝试了几种用于拉取模板/上游更改的变体。以下是我使用过的一些命令。

我已将模板仓库设置为upstream使用git remote add upstream <template-repo-url>

git pull upstream main
git merge upstream/main

如果我使用模板 repo 方法并从子项中提取,我会在第一次提取时出现不相关的历史错误。但是,如果我使用--allow-unrealted-histories.

最后,我想知道如何从单个提交开始从父仓库创建子仓库并获取所有更改(提交)(我更喜欢使用 rebase,因为这将为子仓库带来单独的提交,以获取有关已修复内容的详细信息)。

Parent repo:
900 commits
--- (at this point I create child repo)
fixed(layout): navbar overlay
feat(demo): add code snippets
child repo:
single commit
--- (Above is all the commits of parent repo in single commit when I created child repo)
(now get all the commits separately)
fixed(layout): navbar overlay
(there might me child repo's own commits...)
feat(demo): add code snippets

我也可以放弃使用模板的想法,如果我能实现上面说明的提交历史。

标签: gittemplatesgithub

解决方案


. 我想从单一提交的新回购开始。

我会简单地获得原始存储库的存档(git archiveGitHub tarball)(意思是最新提交的内容,没有任何历史记录,因此没有 900 个以前的提交)

我会在一个新的存储库中扩展该存档,添加README原始存储库的 URL,以防需要浏览这些文件的过去历史记录。


推荐阅读