git: push a single commit

后端 未结 4 776
一整个雨季
一整个雨季 2020-12-02 22:33

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

4条回答
  •  囚心锁ツ
    2020-12-02 22:48

    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:

    • Pushing a commit pushes all commits before it (as Amber said). The key is to reorder your commits (git rebase -i) first, so they are in the order you want to push them.
    • The suggested branch + cherry-pick method (suggested by midtiby) works too, but why create throwaway branches when you don't need to.
    • 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).

提交回复
热议问题