What does cherry-picking a commit with Git mean?

前端 未结 12 2301
梦毁少年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:21

    It will apply a particular commit to your current branch.

    This means :

    • all files added by this commit will be added
    • all files deleted by this commit will be deleted
    • all files modified by this commit will be merged. This means the whole file from the commit, not only the changes from this commit!

    Ex: Consider commit A

    added newFileA
    modified main:
    + import './newFileA'
    

    commit B

    added newFileB
    modified main:
    + import './newFileB'
    

    If you cherry-pick commit B on another branch, you'll end up with :

    /newFileB
    /main :
       import './newFileA'
       import './newFileB'
    

    since commit B contains newFileB and main, but no newFileA, resulting in a bug, so use with caution.

提交回复
热议问题