简体   繁体   English

如何从两个仓库之间的差异创建一个git补丁,但保留历史?

[英]How to create a git patch from the differences between 2 repos but keep the history?

The code in our repo was originally a copy of a download of the source rather than a git clone (the repo wasn't available at the time) So when doing a git blame, a lot of the files are the author who downloaded the code. 我们仓库中的代码原本是源代码下载的副本,而不是git克隆(当时仓库不可用),所以当进行git怪时,很多文件都是由下载该代码的作者创建的。

We have since made a lot of changes to the code. 此后,我们对代码进行了很多更改。

But we now have access to the original repo, so I'd like to add the git history from the original repo. 但是我们现在可以访问原始存储库,因此我想从原始存储库添加git历史记录。 I just wondered if this was possible? 我只是想知道这是否可能?

If I do 如果我做

cd originalrepo
git checkout taggedversionineed
git log

Copy the last commit hash 复制最后的提交哈希

cd ../ourcode
git remote add upstream ../originalrepo
git fetch upstream
git checkout develop
git diff taggedversionhash

It happily shows the differences between the 2 but without the history. 它愉快地显示了两者之间的差异,但没有历史记录。

If I try 如果我尝试

git format-patch taggedversionhash --stdout > ../mypatch.patch

It seems to add all the commits, not just the code differences. 似乎添加了所有提交,而不仅仅是代码差异。 So when I do 所以当我这样做

git checkout -b feature_updatehistory taggedversionhash
git am < ../mypatch.patch

I get lots and lots of 我得到很多

Applying: commitmessage
error: patch failed: filename:387
error: filename: patch does not apply
Patch failed at 0001 commitmessage
The copy of the patch that failed is found in:
   /home/username/www/mycode/.git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

The files are exactly the same, but our file is from the downloaded source, the commit in the patch is from the original repo. 文件完全相同,但是我们的文件来自下载的源,补丁中的提交来自原始存储库。

Any ideas? 有任何想法吗? Is there a better way to do this? 有一个更好的方法吗?

您是否尝试过将丢失了历史记录的分支中的更改挑选到从可用仓库中克隆的分支上?

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

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