git - 如何 merge Git 中的特定提交

标签 git merge

我从 GitHub 的存储库中 fork 了一个分支,并提交了一些特定于我的内容。现在我发现原始存储库有一个很好的功能,它位于 HEAD

我只想在没有先前提交的情况下 merge 它。我应该怎么办?我知道如何 merge 所有提交:

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 ' 应该是您的答案。

Apply the change introduced by an existing commit.

不要忘记阅读 bdonlan在这篇文章中关于 cherry-pick 的后果的回答:
"Pull all commits from a branch, push specified commits to another" ,其中:

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

变成:

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

The problem with this commit 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 - 如何 merge Git 中的特定提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/881092/

相关文章:

mysql - 合并2个mysql表数据库

R:从动物园对象列表中获取单个数据框

sql-server - 合并到没有行

java - java 的 SourceTree 预提交失败

Git 和 Github 工作流程,使用父级更改更新子树

git - 如何将一个 repo rebase 到另一个

git - Heroku Git Repo 是公开的吗?

Git:在 merge 冲突时查看自上次 merge 以来其分支上的更改

git - Git 还原后 merge

git - merge 提交的 git show --raw 输出中的 MM 代表什么?