Cherry picking is the act of picking a commit from a branch and applying it to another. git cherry-pick can be useful for undoing changes. For example, say a commit is accidently made to the wrong branch. You can switch to the correct branch and cherry-pick the commit to where it should belong.
A safe approach is to create a local branch (i.e. xyz) first and then pull the remote branch into your locals. Here is the syntax that could pull a remote branch to a local branch. Perfect! I just didn't know that syntax: git pull {repo} {remotebranchname}:{localbranchname}.
Since "zebra" is a remote branch, I was thinking I don't have its data locally.
You are correct that you don't have the right data, but tried to resolve it in the wrong way. To collect data locally from a remote source, you need to use git fetch
. When you did git checkout zebra
you switched to whatever the state of that branch was the last time you fetched. So fetch from the remote first:
# fetch just the one remote
git fetch <remote>
# or fetch from all remotes
git fetch --all
# make sure you're back on the branch you want to cherry-pick to
git cherry-pick xyz
Just as an addendum to OP accepted answer:
If you having issues with
fatal: bad object xxxxx
that's because you don't have access to that commit. Which means you don't have that repo stored locally. Then:
git remote add LABEL_FOR_THE_REPO REPO_YOU_WANT_THE_COMMIT_FROM
git fetch LABEL_FOR_THE_REPO
git cherry-pick xxxxxxx
Where xxxxxxx is the commit hash you want.
$ git remote add foo git://github.com/foo/bar.git
$ git fetch foo
foo
)$ git log foo/master
$ git cherry-pick 97fedac
After merging a development branch to master, I usually delete the development branch. However, if I want to cherry pick the commits in the development branch, I have to use the merge commit hash to avoid "bad object" error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With