git:将通过提交引入的更改应用于另一个回购 [英] git: Apply changes introduced by commit in one repo to another repo

查看:114
本文介绍了git:将通过提交引入的更改应用于另一个回购的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本地机器上有一个 repo1 repo2 。他们非常相似,但后者是某种其他分支( repo1 不再被维护)。

  / path / to / repo1 $ git log HEAD〜5..HEAD〜4 
< some_sha> Add:Introduce feature X

如何应用commit < some_sha> ; in repo1 repo2



我需要准备一些补丁吗,还是可以在repos之间做一些 cherry-pick



如何做同样的事情,但对于提交的范围? 解决方案

作为一个黑客,你可以尝试修改用于比较GitTips页面上两个不同存储库中的提交的配方,即: p>

  GIT_ALTERNATE_OBJECT_DIRECTORIES = .. / repo / .git / objects \ 
git cherry-pick $(git --git- dir = .. / repo / .git rev-parse --verify< commit>)

其中 ../ repo 是另一个存储库的路径。

使用现代Git,您可以使用多个修订版本和修订范围, cherry-pick 。 p>

$(git --git-dir = .. / repo / .git rev-parse --verify< commit>)
在这里翻译< commit> (例如 HEAD ,或 v0.2 master〜2 ,这是您复制的第二个存储库中的值)转换为SHA-1标识符承诺。如果您知道您想要选择的更改为SHA-1,则不需要。



注意,但Git可以跳过复制对象因为它不知道替代对象存储库只是一个操作的临时存储库。您可能需要从第二个存储库复制对象:

  GIT_ALTERNATE_OBJECT_DIRECTORIES = .. / repo / .git / objects git repack  - a -d -f 

这将从第二个存储库借用的对象放入原始存储库存储中



未经测试。






hacky解决方案是遵循 knittl answer


  • 转到您想要复制提交的第二个存储库,并使用 git format-patch

  • (可选)将修补程序(0001- *等)复制到您的存储库中
  • 使用 git am --3way li>

I have a repo1 and repo2 on local machine. They are very similar, but the latter is some kind of other branch (repo1 is not maintained anymore).

/path/to/repo1 $ git log HEAD~5..HEAD~4
<some_sha> Add: Introduce feature X

How to apply changes made by commit <some_sha> in repo1 to repo2?

Do I need to prepare some patch, or is it possible to do some cherry-pick between the repos?

How about doing the same but for range of commits?

解决方案

As a hack, you can try modifying recipe for comparing commits in two different repositories on GitTips page, i.e.:

GIT_ALTERNATE_OBJECT_DIRECTORIES=../repo/.git/objects \
git cherry-pick $(git --git-dir=../repo/.git rev-parse --verify <commit>)

where ../repo is path to the other repository.

With modern Git you can use multiple revisions and revision ranges with cherry-pick.

The $(git --git-dir=../repo/.git rev-parse --verify <commit>) is here to translate <commit> (for example HEAD, or v0.2, or master~2, which are values in the second repository you copy from) into SHA-1 identifier of commit. If you know SHA-1 of a change you want to pick, it is not necessary.

NOTE however that Git can skip copying objects from source repository, as it doesn't know that the alternate object repository is only temporary, for one operation. You might need to copy objects from the second repository with:

GIT_ALTERNATE_OBJECT_DIRECTORIES=../repo/.git/objects git repack -a -d -f

This puts those objects borrowed from second repository in original repository storage

Not tested.


A not so hacky solution is to follow knittl answer:

  • Go to second repository you want to copy commits from, and generate patches from commits you want with git format-patch
  • Optionally, copy patches (0001-* etc.) to your repository
  • Use git am --3way to apply patches

这篇关于git:将通过提交引入的更改应用于另一个回购的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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