Someone fixed an error in a program on Github, but it hasn't been added to the master branch. I want to just pull this one commit, but everything I've tried gives an error saying bad object.
Asked
Active
Viewed 1.0k times
1 Answers
18
It would be easier to:
git fetch
(the brings everything locally)git cherry-pick <SHA1 of the right commit>
Once the fetch is done, you can cherry-pick the commit which fixes the error (it should be part of git log origin/xxx
, with xxx
being the branch where the bug fix was committed on the GitHub side)
Once the bug fix locally cherry-picked in the local master
branch, a simple git push will publish that new commit on the GitHub master
branch.
If the commit is from another fork:
git remote add otherfork /url/to/other/fork
git fetch otherfork
git cherry-pick <commit>
-
Running cherry-pick with the hash gives `fatal: bad object 67be47b408d15d433d85044dca7d21f1cbfdae0a` – Kookerus Apr 13 '15 at 13:46
-
@Kookerus did you do a `git fetch` first? – VonC Apr 13 '15 at 13:47
-
I did. I cloned the repo, ran `git fetch`, and then `git cherry-pick 67be47b408d15d433d85044dca7d21f1cbfdae0a` – Kookerus Apr 13 '15 at 13:48
-
@Kookerus is that SHA1 visible in the GitHub repo whose url matches '`origin`' when doing a `git remote -v`? – VonC Apr 13 '15 at 13:53
-
@Kookerus Or is `67be47b408d15d433d85044dca7d21f1cbfdae0a` visible in *another* repo (like a fork)? – VonC Apr 13 '15 at 13:54
-
It is, and it's got the fix I need. – Kookerus Apr 13 '15 at 14:01
-
@Kookerus As in http://stackoverflow.com/a/13789405/6309, try a `git fetch --all` first. – VonC Apr 13 '15 at 14:05
-
@Kookerus or, as in http://stackoverflow.com/a/27145793/6309, check if the commit is in the same repo (or in a submodule) – VonC Apr 13 '15 at 14:06
-
I'm still getting `Fatal: bad object` – Kookerus Apr 13 '15 at 14:09
-
@Kookerus It should be simple: if you can see that commit in a `gitk --all`, as in http://gitready.com/intermediate/2009/03/04/pick-out-individual-commits.html, you should be able to cherry-pick it without any issue (provided you are on the master branch: `git checkout master` first) – VonC Apr 13 '15 at 14:28
-
I feel like a complete moron. The commit was from another fork, and because I still don't understand github very well, I thought it was from the original repo. Sorry for wasting your time. – Kookerus Apr 13 '15 at 14:37
-
1@Kookerus No problem. I have edited the answer to reflect the actual solution. – VonC Apr 13 '15 at 14:39
-
Thanks, I never even thought of just adding the other fork. – Kookerus Apr 13 '15 at 15:54