git - cherry-pick - HOWTO / WHYTO

前端 未结 3 1533
梦谈多话
梦谈多话 2020-11-28 15:32

Problem: You want to test a feature someone has developed, but it only exists in a remote branch which is woefully out of date.

Source

3条回答
  •  时光取名叫无心
    2020-11-28 15:52

    From git help cherry-pick:

    git-cherry-pick - Apply the changes introduced by some existing commits

    [...]

    Given one or more existing commits, apply the change each one introduces, recording a new commit for each. This requires your working tree to be clean (no modifications from the HEAD commit).

    So, when you cherry-pick a commit, git takes that commit's changes (its diff) and tries to apply it on your current working directory, creating a new commit that is equivalent to the one you are cherry-picking.

    It's a way to re-do another commit's changes on a different history line.

    Besides taking the changes, cherry-pick also preserves the original commit's info like author and that.

    Lastly, cherry-pick can receive a group of commits to apply, in which case it would act like cherry-picking them one by one, in chronological order (older first).

提交回复
热议问题