Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

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

like image 240
whenov Avatar asked Dec 30 '13 09:12

whenov


People also ask

What is the difference between cherry pick and merge?

With the cherry-pick command, Git lets you incorporate selected individual commits from any branch into your current Git HEAD branch. When performing a git merge or git rebase , all the commits from a branch are combined. The cherry-pick command allows you to select individual commits for integration.

Do you cherry pick merge commits?

With the "cherry-pick" command, Git allows you to integrate selected, individual commits from any branch into your current HEAD branch. Contrast this with the way commit integration normally works in Git: when performing a Merge or Rebase, all commits from one branch are integrated.

How do you do cherry pick without commit?

The --no-commit option will execute the cherry pick but instead of making a new commit it will move the contents of the target commit into the working directory of the current branch.

What is git merge No commit?

With --no-commit perform the merge and stop just before creating a merge commit, to give the user a chance to inspect and further tweak the merge result before committing. Note that fast-forward updates do not create a merge commit and therefore there is no way to stop those merges with --no-commit.


2 Answers

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.

like image 51
gturri Avatar answered Oct 11 '22 21:10

gturri


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.

like image 42
Ahmed Siouani Avatar answered Oct 11 '22 22:10

Ahmed Siouani