开发者

In what instance would git cherry-pick be needed instead of git merge?

For moving an individual from one branch to another I realize that there are a few options in git. I have experimented with git merge and git cherry-pick but am failing to see when git cherry-pick is preferable.

My understanding is the following:

git merge <hash> moves the specified commit from one branch to the other开发者_如何学Python preserving it as one commit.

git cherry-pick <hash> creates a copy of the commit in the second branch but it is separate with its own commit hash.

The first option seems preferable to me but what are the instances when cherry-pick would be preferred?


Say you have a branch from master that has a bunch of commits. Maybe you made a change that is appropriate on master, but you don't want to bring in all of the changes (a small bug fix, for example, or the addition of a small feature). With git cherry-pick, you can grab only that commit from the other branch and bring it into master.


Another use case is when you lose a commit and want to get it back. http://www.programblings.com/2008/06/07/the-illustrated-guide-to-recovering-lost-commits-with-git/

mathieu@ml recovery (master)$ git cherry-pick 93b0c51cfea8c731aa385109b8e99d19b38a55be Finished one cherry-pick. Created commit f443703: Now that was cool 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 cool_file

You need to have the hash of course.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜