git: push a single commit
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). Will reordering with rebase, resetting, pushing and then resetting work? (C1->C2->C3->C4 => C2->C4->C1->C3 => reset C4 => push => reset C3). Is there a nicer way?
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).
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).
$ git push <remote name> <commit hash>:<remote branch name>
# Example:
$ git push origin 2dc2b7e393e6b712ef103eaac81050b9693395a4:master
链接地址: http://www.djcxy.com/p/8770.html
上一篇: git:在本地再次访问之后重复提交
下一篇: git:推送一个提交