how do you push only some of your local git commits?

前端 未结 5 1497
予麋鹿
予麋鹿 2020-11-29 15:02

Suppose I have 5 local commits. I want to push only 2 of them to a centralized repo (using an SVN-style workflow). How do I do this?

This did not work:

<         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 15:31

    Short answer:

    git push

    Examples:

    git push fc47b2

    git push HEAD~2

    Long answer:

    Commits are linked together as a chain with a parent/child mechanism. Thus, pushing a commit actually also pushes all parent commits to this commit that where not known to the remote. This is implicitly done when you git push the current commit: all the previous commits are also pushed because this command is equivalent to git push HEAD.

    So the question might be rewritten into How to push a specific commit and this specific commit might be HEAD~2, for example.

    If the commits you want to push are non-consecutive, simply re-order them with a git rebase -i before the specific push.

提交回复
热议问题