Say I made several commits and wish to cherry pick which ones I push to the remote repository. How can I do that (in ascii: C1->C2->C3->C4 and I want to push C2 and C4). Wil
IIRC, due to how git considers commits to work, C4 inherently includes C3, so the concept of "pushing C4 but not C3" doesn't make sense to git (and likewise C2 relative to C1). (See the answer to this previous question.)
What you're looking for:
git push origin commit-id:master
Credit goes to: http://blog.dennisrobinson.name/push-only-one-commit-with-git/
Explanatory notes:
git rebase -i
) first, so they are
in the order you want to push them.commit-id
doesn't have to be a sha1. To push everything before the
last N commits, use "HEAD~N" in place of commit-id
.If pushing to a branch that doesn't exist in the remote repository yet, prefix the remote branch with refs/heads/
, such as:
git push origin HEAD~1:refs/heads/completely-new-branch
(If not, git will punish you with this hopeless error message).
If you have your commits on a private branch, you can cherry pick commits from the private branch and apply them to the official branch. At this point you can now push all your commits on the official branch (which is the subset that you previously cherry picked).
$ git push <remote name> <commit hash>:<remote branch name>
# Example:
$ git push origin 2dc2b7e393e6b712ef103eaac81050b9693395a4:master