合并同一项目的两个git存储库 [英] Merge two git repositories of same project

查看:205
本文介绍了合并同一项目的两个git存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我是唯一从事从前任接手的项目的开发人员.当我接管该项目时,它不受源代码控制.因此,我创建了一个新的git存储库,并对该状态进行了首次提交并自此进行了处理.

I am currently the only developer working on a project I took over from my predecessor. When I took over the project, it was not under source control. So I created a new git repository, made an initial commit with the state and worked on it since.

但是最近我在备份中发现了同一项目的一个古老版本,该版本实际上是一个git存储库,但是,由于我的前任对git一无所知,他从中复制了所有文件,并在没有源代码控制的情况下对它们进行了处理.

But recently I discoveered in a backup an ancient version of the same project, which actually is a git repository, however, as my predecessor knew nothing about git, he copied all files out of it and worked on them without source control.

因此,我现在有两个git存储库,一个包含到特定日期的所有更改,另一个包含从以后的日期到现在的所有更改.但是在这两者之间,没有源代码控制存在差距.

So, I now have two git repositories, one contains all changes up to a certain date, the other all changes from a later date up until now. But in between, there is a gap without source control.

是否可以合并这两个存储库,使它似乎总是作为一个存储库存在,但是在没有源代码控制的情况下所做的更改是它们之间的一个大提交?

Is it possible to merge these two repository such that it seems that it always existed as one single repository, but with the changes made without source control as one big commit in between?

推荐答案

当然,请使用ours策略!

遵循以下步骤(以#开头的行是注释):

Follow the the next steps (lines starting with # are comments):

# Navigate to your updated project
cd your-updated-project

# Add a remote pointing to the other git repository 
# (it can be a local path or an url; I used a local path)
git remote add old-project ../path/to/the/old/git/repo

# Get the content from that repo
git fetch old-project

# Merge the the old repo master branch in your current branch,
# BUT keeping your recent changes (see -s ours)
git merge old-project master -s ours

如果要合并旧git repo中的另一个分支,请执行git merge old-project <branch-name> -s ours(用要合并的分支名称替换<branch-name>).

If you want to merge another branch from the old git repo, do git merge old-project <branch-name> -s ours (replace <branch-name> with the branch name you want to merge).

这篇关于合并同一项目的两个git存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆