Git cherry-pick syntax and merge branches

后端 未结 6 1194
梦毁少年i
梦毁少年i 2020-12-12 19:05

So I have done countless cherry picks before and it seems that I must fail at life with this right now, I am trying to cherry pick from one branch to another which should be

6条回答
  •  不思量自难忘°
    2020-12-12 19:42

    The git is requesting you to specify parent number (-m), because your merge commit has two parents and git do not know which side of the merge should be considered the mainline. So using this option you can specify the parent number (starting from 1) of the mainline and cherry-pick in order to replay the change relative to the specified parent.

    To find out your commit parents, try either:

    git show --pretty=raw 
    

    or:

    git cat-file -p 
    

    or even for better GUI visibility, try:

    gitk 
    

    As result, you should get something like:

    commit fc70b1e9f940a6b511cbf86fe20293b181fb7821
    tree 8d2ed6b21f074725db4f90e6aca1ebda6bc5d050 
    parent 54d59bedb9228fbbb9d645b977173009647a08a9 = 
    parent 80f1016b327cd8482a3855ade89a41ffab64a792 = 
    

    Then check your each parent details by:

    git show 
    

    Add --stat to see list of modified files.

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

    git diff ..
    

    Add --stat to see list of modified files.

    or use the combined diff to compare the two parents by:

    git diff --cc 
    git diff --cc 
    

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

    git cherry-pick -m 1 
    

    Then run git status to see what's going on. If you don't want to commit the changes yet, add -n option to see what happens. Then when you're not happy, reset to HEAD (git reset HEAD --hard). If you'll get git conflicts, you'll probably have to solve them manually or specify merge strategy (-X), see: How to resolve merge conflicts in Git?

提交回复
热议问题