如何合并Git中的特定提交 [英] How to merge a specific commit in Git

查看:95
本文介绍了如何合并Git中的特定提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从GitHub的存储库中分支出了一个分支,并为我提供了一些特定的东西。现在我发现原始存储库有一个很好的功能,它位于 HEAD



我只想合并它先前的提交。我该做什么?我已经知道如何合并所有提交:

  git branch -b a-good-feature 
git pull repository master
git checkout master
git merge a-good-feature
git commit -a
git push


解决方案

' git cherry-pick '应该是您的答案。


应用现有提交引入的更改。


不要忘记阅读 bdonlan 的回答关于樱桃采摘在这篇文章中的后果:

从分支中提取所有提交,将指定的提交推送到另一个,其中:

  A ----- B ------ C 
\
\
D
code>

变成:

  A ----- B ------ C 
\
\
D ----- C'




这个提交的问题在于git认为提交包含所有历史记录



其中C'具有不同的 SHA-1 ID。

同样,樱桃挑选从一个分支到另一个分支的提交基本上涉及生成补丁,然后应用它,从而失去了w的历史


这种提交ID的改变打破了git的合并功能(尽管如果少用启发式文件将会对此有所论述)。

更重要的是,忽略了函数依赖关系 - 如果C实际上使用了B中定义的函数,那么您永远都不会知道


I have forked a branch from a repository in GitHub and committed something specific to me. Now I found the original repository had a good feature which was at HEAD.

I want to merge it only without previous commits. What I should do? I have known how to merge all commits:

git branch -b a-good-feature
git pull repository master
git checkout master
git merge a-good-feature
git commit -a
git push

解决方案

'git cherry-pick' should be your answer here.

Apply the change introduced by an existing commit.

Do not forget to read bdonlan's answer about the consequence of cherry-picking in this post:
"Pull all commits from a branch, push specified commits to another", where:

A-----B------C
 \
  \
   D

becomes:

A-----B------C
 \
  \
   D-----C'

The problem with this commits is that git considers commits to include all history before them

Where C' has a different SHA-1 ID.
Likewise, cherry picking a commit from one branch to another basically involves generating a patch, then applying it, thus losing history that way as well.

This changing of commit IDs breaks git's merging functionality among other things (though if used sparingly there are heuristics that will paper over this).
More importantly though, it ignores functional dependencies - if C actually used a function defined in B, you'll never know.

这篇关于如何合并Git中的特定提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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