Git swirl and join syntax

So, I have already made countless cherries, and it seems to me that I can’t deal with it now, I’m trying to choose from one branch to another, which should be easy, however, I am mistaken, the merger was received, but not -m?

$ git cherry-pick a8c5ad438f6173dc34f6ec45bddcef2ab23285e0 error: Commit a8c5ad438f6173dc34f6ec45bddcef2ab23285e0 is a merge but no -m option was given. fatal: cherry-pick failed 

This doesn't look right ... should be:

 $ git cherry-pick a8c5ad438f6173dc34f6ec45bddcef2ab23285e0 

So how, when do I need to provide the -m function?

+49
git git-cherry-pick cherry-pick
Sep 27 '12 at 17:16
source share
5 answers

You must specify -m if the commit is a merge commit, i.e. commit with multiple parents.

Usually, git cherry-pick REV can be described as:

  • Take the change between rev and its parent.

  • Apply these changes to the current HEAD and commit the result with the commit message rev.

Merge approval combines two lines of development. For example, one row implements a widget, and another row removes the clutter. Merging gives you code with widgets, without interference.

Now, consider step # 1 of the cherry pick process: git cannot guess if you want to remove the clutter or implement the widget. You also cannot do both, because the information on how to do this is not contained within a single merge, only the contents of the resulting merged tree.

The -m allows you to tell git how to proceed. For example, if the removal of interference occurred in master , and the merge merge was created using git merge WIDGET , then git cherry-pick -m 1 merged-commit will cherry-select a new widget, because the diff is between the merged tree and the parent 1 (the last of removing interference commits) will be just adding a widget. On the other hand, git cherry-pick -m 2 merge-commit will remove the clutter, because the difference between parent 2 (the last of the widget add commits) and merge-commit is precisely the clutter removal that is not in the widget branch.

+64
Sep 27 '12 at 19:17
source share

git asks for the parent number ( -m ) because your merge has two parents and git don’t know which side of the merge should be considered the main one. Thus, using this parameter, you can specify the parent number (starting from 1) of the main line and cherry selection to reproduce the change relative to the specified parent.

To get to know your parents, try either:

 git show --pretty=raw <merge_commit> 

or

 git cat-file -p <merge_commit> 

or even for better visibility of the GUI, try:

 gitk <merge_commit> 

As a result, you should get something like:

 commit fc70b1e9f940a6b511cbf86fe20293b181fb7821 tree 8d2ed6b21f074725db4f90e6aca1ebda6bc5d050 parent 54d59bedb9228fbbb9d645b977173009647a08a9 = <parent1_commit> parent 80f1016b327cd8482a3855ade89a41ffab64a792 = <parent2_commit> 

Then check all your parent data for:

 git show <parent1_or_2_commit> 

Add --stat to see a list of modified files.

Or use the following command to compare changes (based on the parent described above):

 git diff <parent1_or_2_commit>..<commit> 

Add --stat to see a list of modified files.

or use combined diff to compare two parents:

 git diff --cc <parent1_commit> git diff --cc <parent2_commit> 

Then specify the parent number starting with 1 for your cherry pick, e.g.

 git cherry-pick -m 1 <merge_commit> 

Then run git status to find out what is happening. If you don’t want to commit the changes yet, add the -n option to see what happens. Then when you are not happy, reset to HEAD ( git reset HEAD --hard ). If you run into git conflicts, you may have to manually resolve them or specify a merge strategy ( -X ), see How to resolve merge conflicts in Git?

+13
Jul 30 '16 at 1:23
source share

Personally, what I usually do, since merging combines 2 commits, for example, if I have a merge with a C commit, which consists of two parents, for example, commit A in master and commit B from another branch receiving the union, if I need to cherry chooses to merge, I wouldn’t bother with a confusing team so that cherry chooses to fix the merge, but instead I just cherry each of the parents A and B individually, this is also useful in a situation where you only want cherry pick commit B only in in case the fixation A from the master was already selected by cherry in etku and cherry - before they merged.

+3
Jan 20 '16 at 16:40
source share

The syntax from the man pages is as follows:

 git cherry-pick [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] <commit>... 

Parent number refers to:

-m parent-number, -mainline parent-number. Usually you cannot use cherry merge because you do not know which side of the merger should be considered the main one. This option indicates the parent number (starting from 1) of the main line and allows the cherry plant to reproduce the change relative to the specified parent.

So, I would double check to make sure you have the correct commit hash. Perhaps you need one that is not from a merger, but rather with a fixation in front of it. Otherwise, you need to use this flag and specify the correct side of the merge to eliminate your request.

+2
Sep 27 '12 at 17:45
source share

Try combining the result:

 git cherry-pick .... git mergetool git cherry-pick --continue 
0
Feb 17 '16 at 9:46
source share



All Articles