我从 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/