You are right - at the first command you just switched to the remote changes, while at the last you applied the remote changes on your current branch.
Besides being used for different tasks, the most significant difference is that git-cherry-pick
changes the history of a branch, while git checkout
is being used only to jump to a specific point in time (a specific commit) in the branch's history, without changing it.
Switch branches or restore working tree files
git-checkout
is used to traverse along your branch history, pointing the HEAD
variable to a specific commit. It is also used to switch between branches
Apply the changes introduced by some existing commits
git-cherrypick
on the other way is used to place a single commit from another branch on top of your branch history.
For example, says you have the following branches:
master:
-------
commit1 1ae4d13257425e6a0d67f35fa13e9d76c4e6987b
Date: Thu Feb 1 15:59:15 2018 +0200
commit2 cbc7776d5542f59e1e6c7c8a22add729b
Date: Thu Feb 1 15:44:41 2018 +0200
branch:
-------
commit1 c591438ff5abbcebcbf9c06f47de7aa840
Date: Thu Feb 1 15:45:24 2018 +0200
You can switch into branch
branch using:
git checkout branch
and from branch
you can execute the following:
git cherry-pick 1ae4d132
to play commit1
from master on top of commit1
from branch, making it:
branch:
-------
commit1 1ae4d13257425e6a0d67f35fa13e9d76c4e6987b
Date: Thu Feb 1 15:59:15 2018 +0200
commit1 c591438ff5abbcebcbf9c06f47de7aa840
Date: Thu Feb 1 15:45:24 2018 +0200
You can use traverse your history and see a single state of it using checkout
:
git checkout c591438ff5
This will points HEAD
to commit c591438ff5
, showing you the state of the branch before your cherry-picking (but it won't change the history)