What does cherry-picking a commit with Git mean?

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

    This quote is taken from; Version Control with Git (Really great book, I encourage you to buy it if you are interested in git)

    Edit: Since this answer is still getting impression, I would like to add very nice in action video tutorial about it:

    Youtube: Introduction to Git cherry-pick

    Using git cherry-pick The command git cherry-pick commit applies the changes introduced by the named commit on the current branch. It will introduce a new, distinct commit. Strictly speaking, using git cherry-pick doesn’t alter the existing history within a repository; instead, it adds to the history. As with other Git operations that introduce changes via the process of applying a diff, you may need to resolve conflicts to fully apply the changes from the given commit . The command git cherry-pick is typically used to introduce particular commits from one branch within a repository onto a different branch. A common use is to forward- or back-port commits from a maintenance branch to a development branch.

    $ git checkout rel_2.3
    $ git cherry-pick dev~2 # commit F, above
    

    before: before

    after: after

提交回复
热议问题