I have the following situation which is different than this one.
Here's my local repo:
$ git branch
branch1
...
branchk
master
* this-branch-where-fix-should-happen
What I want is to apply a commit that only exists in the upstream:staging
branch.
I've tried to fetch upstream in a certain branch
$ git fetch upstream staging:staging
From github.com:<org>/<repo>
* [new branch] staging -> staging
New output from branch
.
$ git branch
branch1
...
branchk
master
staging
* this-branch-where-fix-should-happen
Now trying to cherry pick into fix-branch
:
$ git cherry-pick -x <sha-1>
fatal: bad object <sha-1>
Is there a correct way to cherry pick in this situation? Or am I doing it the completely wrong way?
Solution: Finding the problem and fixing it
As instructed by Tim Biegeleisen
Fetching upstream
$ git fetch upstream
This is where my mistake was, I was getting the commit number via the github site, however that was actually a <sha-1>
for the merge. To get the correct commit number:
$ git log --pretty=oneline --grep="<some-info-about-the-commit>" upstream/staging
I've used --grep="#pull-request-number"
and got the correct commit id.
<correct-sha-1> PR description (#PR-number)
Now trying to cherry pick into fix-branch
:
$ git cherry-pick -x <correct-sha-1>
And it works!