[英]Merge commits of two repos sequentially
I have two repos old_repo
and new_repo
. 我有两个repos
old_repo
和new_repo
。 old_repo
has 10 commits. old_repo
有10个提交。 new_repo
has 20 commits. new_repo
有20个提交。 Date of all commits of new_repo
are later than those of old_repo
. new_repo
的所有提交日期晚于old_repo
。 I want to prepend 10 commits of old_repo
to the beginning of new_repo
such that the resultant repo has 30 commits in the same order in which they were originally created. 我要在前面加上的10个提交
old_repo
至年初new_repo
使得所得回购在它们被最初创建相同的顺序30次的提交。 What are possible ways to do it. 有哪些方法可以做到这一点。
One obvious and tiresome approach that I can think of is cherry picking and appending to the old_repo
each commit of new_repo
one by one. 我能想到的一个显而易见且令人讨厌的方法是樱桃挑选并
old_repo
追加到old_repo
每次提交new_repo
。 Looking for better suggestions. 寻找更好的建议。
PS: the file changes between the 10th and 11th commits are not supposed to be drastic as they were once the same repo but .git
folder got deleted accidentally which broke the commit sequence. PS:第10次提交和第11次提交之间的文件更改不应该是激烈的,因为它们曾经是同一个repo但
.git
文件夹被意外删除而这违反了提交顺序。
I want to prepend 10 commits of old_repo to the beginning of new_repo such that the resultant repo has 30 commits in the same order in which they were originally created.
我想在new_repo的开头添加10次old_repo提交,以便生成的repo按照最初创建的顺序进行30次提交。
Git commits are a graph meaning there's multiple ways to interpret the order of commits. Git提交是一个图表,意味着有多种方法来解释提交顺序。 By date.
按日期。 Or "topological".
或者“拓扑”。 Preserving the order in which they were created means date order, but it's really not that important in Git.
保留它们的创建顺序意味着日期顺序,但它在Git中并不那么重要。
You have two options: merge them or rebase them. 您有两种选择:合并它们或重新定义它们。 Which you choose depends on what outcome you want.
你选择哪个取决于你想要的结果。
In either case, make old_repo
a remote of new_repo
so the repositories can see each other. 在任一情况下,使
old_repo
的远程new_repo
所以储存库可以看到对方。
git remote add old_repo <path or url to old_repo>
git fetch old_repo
Merge old_repo/master
into the new_repo's master
. 将
old_repo/master
合并到new_repo的master
。
git checkout master
git merge --allow-unrelated-histories old_repo/master
Resolve conflicts as normal. 正常解决冲突。 And you're done.
而且你已经完成了。 The history of both repos is now merged like so.
两个回购的历史现在合并如此。 And as you can see "date order" doesn't really matter.
正如你所看到的“日期顺序”并不重要。 The original two branches preserved in the history .
原始的两个分支保存在历史中 。
O1 ... O8 - O9 - O10
\
M [master]
/
N1 ... N18 - N19 - N20
This is like cherry picking each commit of new_repo
on top of old_repo
, but Git can do this for you. 这就像在
new_repo
上挑选new_repo
每次提交old_repo
,但是Git可以为你做这个。
git checkout master
git rebase old_repo/master
This will replay all the commits on new_repo's master branch on top of old_repo's master branch. 这将在old_repo的主分支上重放new_repo主分支上的所有提交。 You'll wind up with one branch of 30 commits.
你将结束30个提交的一个分支。 No evidence that they were ever two different repositories remains .
没有证据表明他们曾经是两个不同的存储库 。
O1 ... O9 - O10 - N1 - N2 ... N20 [master]
In either case it's safe to delete the remote to the old repo. 在任何一种情况下,将遥控器删除到旧的仓库都是安全的。
git remote rm old_repo
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.