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

前端 未结 5 1499
予麋鹿
予麋鹿 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:44

    What I do is work on a local branch called "work". This branch contains all the temporary commits (like workarounds or private build options or whatever) that I don't intend to push to the upstream repository. I work away on that branch, then when I want to commit I switch to the master branch, cherry-pick the appropriate commits that I do want to commit, then push master.

    After pulling changes from the upstream into my master branch, I git checkout work and git rebase master. That rewrites all my local changes to be at the end of the history.

    I'm actually using git svn with this workflow, so my "push" operation involves git svn dcommit. I also use tig which is a nice text mode gui repository viewer, to cherry-pick the appropriate commits to master.

提交回复
热议问题