简体   繁体   中英

What does “git cherry-pick origin/master” mean?

What does git cherry-pick origin/master mean? How does this instruction work?

When updating current local master branch from remote (ie, fetch data from remote and merge with local files), we could use the following options:

  • git pull origin master
  • git fetch origin master; git merge origin/master
  • git fetch origin master; git rebase origin/master
  • git fetch origin master; git cherry-pick origin/master

But I cannot understand git cherry-pick origin/master and cannot find the explanation.

I am curious about the following things: when I use git fetch origin master; git cherry-pick origin/master git fetch origin master; git cherry-pick origin/master to try to update current local master branch from remote, this action compares previous commits and brings the different parts as modified files, so I can use one commit to includes these modified parts. How does it work?

While merge and rebase work with multiple commits by default, cherry-pick operates on only one commit by default. The cherry-pick command above will not include all commits from origin/master unless specified (or if there's only one additional commit between origin/master and local master ).

Issuing git cherry-pick origin/master will take the single commit at the tip of origin/master and apply it to the current working branch.

In addition to how the three commands operate with commits, there are other differences which can be found by looking at the git documentation.

This is a good explanation of cherry-pick : What does cherry-picking a commit with git mean?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM