简体   繁体   English

git合并并保留原始回购记录中的历史记录

[英]git merge and keep history from original repo

Originally we only had access to a zip of the source code. 最初,我们只能访问源代码的zip。

So we downloaded, unzipped, created a git repo and pushed. 因此,我们下载,解压缩,创建了一个git repo并进行了推送。

So there wasn't any git history except from our initial commit. 因此,除了我们最初的提交以外,没有任何git历史记录。

Now we have access to the original repo so would like to merge and upgrade. 现在我们可以访问原始存储库,因此希望合并和升级。

Here is what I have done so far 这是我到目前为止所做的

Add the original repo 添加原始回购

git remote add upstream url_to_their_repo
git fetch upstream

Create a blank branch 创建一个空白分支

git checkout --orphan upgrade
git rm -rf .

Merge their code into the upgrade branch 将他们的代码合并到升级分支中

git merge upstream/theirbranch

Copy our code on top 在顶部复制我们的代码

git merge master

It shows a few conflicts which need to be resolved but when I do 它显示了一些需要解决的冲突,但是当我这样做时

git blame filename

It shows the developer who did our initial commit rather than the original repo history. 它显示了执行我们最初提交而不是原始回购历史记录的开发人员。

Is there a way to just copy the history for changes we have made? 有没有一种方法可以仅复制历史记录来进行更改?

I would rebase my changes on top of the new repository 我将基于新存储库进行更改

                    upstream/master
                    |
                    V
A---B---C---D---E---F

G---H---I
        ^
        |
        master

First create a local branch from upstream/master 首先从upstream/master创建本地分支

git branch upstreamMaster upstream/master

Then rebase your changes onto upstreamMaster , but omit your first commit. 然后将您的更改重新基于upstreamMaster ,但忽略您的第一次提交。 Since the first commit contains all files (unzipped project was committed) it will lead to conflicts. 由于第一次提交包含所有文件(提交了未压缩的项目),这将导致冲突。 Furthermore you only need your changes so start at commit H . 此外,您只需要更改,因此从提交H开始。

git rebase --onto upstreamMaster H master

You can use 您可以使用

git log --pretty=format:%H master |tail -1

to find the first commit of master. 找到主人的第一次提交。

After the rebase your repository will look like this 重新设置基础之后,您的存储库将如下所示

                    upstream/master
                    |
                    V
A---B---C---D---E---F---H---I
                    ^       ^
                    |       |
       upstreamMaster       master

Now you can fast forward the upstreamMaster 现在您可以快进upstreamMaster

git checkout upstreamMaster
git merge master

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM