Can two identically structured git repos be merged when they have never had any common history?

半腔热情 提交于 2019-11-29 19:56:49

问题


I have two small git repos. The projects both started from different points but converged to a very similar one (same file names, folder structure, etc). One is not a branch of the other, but one can be considered an evolution of the other.

It would be nice if I could merge the two so that repo2 is the continuation of repo1. Is this possible, whilst adding the history of repo2 to the end of repo1's?


回答1:


You can fetch one into another:

$ cd project1
$ git config remote.project2.url /path/to/project2
$ git config remote.project2.fetch 'refs/heads/*:refs/project2/*'
$ git fetch project

That will give you two (or more) branches, containing history of the project1 and project2. They are still completely independent, just use the same object store.

Then (not tested), you could use a graft file (.git/info/grafts) where you could overwrite the parenthood of a commit (like the first of project2 having for parent the latest of project1)

As Dustin says in the comments, a rebase is in order in order to "make it permanent", by replaying project2 commits onto project1.


You have another illustration in this "Using Git within a project (forking around)" blog entry, especially the section "How to pull friends and influence people". Again:

git checkout two_point_ooh
git remote add strelau git://gitorious.org/ruby-on-rails-tmbundle/mainline.git
git checkout -b strelau/two_point_ooh
git pull strelau two_point_ooh

is a similar process, but for repositories which are forked (which is not exactly your case)



来源:https://stackoverflow.com/questions/651542/can-two-identically-structured-git-repos-be-merged-when-they-have-never-had-any

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!