git merge --no-commit vs git cherry-pick --no-commit

拜拜、爱过 提交于 2019-12-03 14:28:13

问题


Is there any difference between git merge --no-commit and git cherry-pick --no-commit?

And is there any difference in history if I commit after these two commands?


回答1:


If you commit after git merge --no-commit, you'll actually get a merge commit. Whereas after a git cherry-pick --no-commit you'll get a commit with a single parent.

Hence, yes, there is a difference between those two commands.

In particular if you have something like

A -- B -- C
 \        L HEAD
  \
   -- D -- E

If you cherry-pick commit E, you won't get modifications of commit D. Whereas if you merge, you'll get both.




回答2:


While git-merge is used to join two or more development histories together, git-cherry-pick is used to apply changes introduced by some existing commits.

So then, once you commit after performing a git-merge, Git will add what's called a merge commit. In the other side, when cherry-pick(ing) commits, git will apply the changes introduced by these commits on the top of your working tree (There's no fusion between two or many branches). Put another way, Commits are cloned and put on top of your branch.

Take a look at Git Cherry-pick vs Merge Workflow to undestand the differences based on a repo maintainer real needs.



来源:https://stackoverflow.com/questions/20837080/git-merge-no-commit-vs-git-cherry-pick-no-commit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!