What does cherry-picking a commit with Git mean?

前端 未结 12 2133
梦毁少年i
梦毁少年i 2020-11-22 11:58

Recently, I have been asked to cherry-pick a commit.

So what does cherry-picking a commit in git mean? How do you do it?

12条回答
  •  盖世英雄少女心
    2020-11-22 12:20

    Cherry picking in Git means to choose a commit from one branch and apply it onto another.

    This is in contrast with other ways such as merge and rebase which normally apply many commits onto another branch.

    1. Make sure you are on the branch you want to apply the commit to.

      git checkout master
      
    2. Execute the following:

      git cherry-pick 
      

    N.B.:

    1. If you cherry-pick from a public branch, you should consider using

      git cherry-pick -x 
      

      This will generate a standardized commit message. This way, you (and your co-workers) can still keep track of the origin of the commit and may avoid merge conflicts in the future.

    2. If you have notes attached to the commit they do not follow the cherry-pick. To bring them over as well, You have to use:

      git notes copy  
      

    Additional links:

    • git official guide page

提交回复
热议问题