简体   繁体   English

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

[英]git merge --no-commit vs git cherry-pick --no-commit

Is there any difference between git merge --no-commit and git cherry-pick --no-commit ? git merge --no-commitgit cherry-pick --no-commit之间有什么区别吗?

And is there any difference in history if I commit after these two commands? 如果我遵循这两个命令后,历史上有什么不同吗?

If you commit after git merge --no-commit , you'll actually get a merge commit. 如果你在git merge --no-commit commit之后git merge --no-commit ,你实际上会得到一个合并提交。 Whereas after a git cherry-pick --no-commit you'll get a commit with a single parent. 然后在git cherry-pick --no-commit你会得到一个单亲的提交。

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 . 如果您cherry-pick提交E ,则不会修改提交D Whereas if you merge , you'll get both. 如果你merge ,你会得到两者。

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. 虽然git-merge用于将两个或多个开发历史记录连接在一起,但git-cherry-pick用于应用某些现有提交引入的更改。

So then, once you commit after performing a git-merge , Git will add what's called a merge commit . 那么,一旦你执行git-merge后提交,Git将添加所谓的合并提交 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). 另一方面,当cherry-pick(ing)提交时,git会将这些提交引入的更改应用到工作树的顶部(两个或多个分支之间没有融合)。 Put another way, Commits are cloned and put on top of your branch. 换句话说,Commits被克隆并放在你的分支之上。

Take a look at Git Cherry-pick vs Merge Workflow to undestand the differences based on a repo maintainer real needs. 看看Git Cherry-pick vs Merge Workflow ,根据repo维护者的实际需求来解决差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM