I\'m having trouble performing a cherry-pick. On my local machine, I\'m currently on my \"master\" branch. I want to cherry-pick in a commit from another branch, named \"zeb
The commit should be present in your local, check by using git log
.
If the commit is not present then try git fetch
to update the local with the latest remote.
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.
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
I solved this issue by going on the branch with the commit I want to cherry pick.
git checkout <branch With Commit To Cherry-Pick>
use log to find commit hash
git log
when you've found your hash cut and paste on note pad. if using command just scroll up to get the hash then checkout the branch you want to place the commit in.
git checkout < branch I Want To Place My Cherry-Picked-Hash In>
finally call cherry-pick from git (note) -x is to append your cherry-pick message to the original. "When recording the commit, append a line that says "(cherry picked from commit …)" to the original commit message in order to indicate which commit this change was cherry-picked from. "
git cherry-pick -x <your hash commit to add to the current branch>