Git rebase –merge with only some of the commits

I did a few commits, say commit A, B, C
Now I want to push only commit A and B to the remote repo. (And keep commit C to be merged and pushed at a later time)
Before I push, I need to run:

git fetch origin master
git rebase --merge FETCH_HEAD

problem is the above commands will ask me to resolve conflicts of commit C as well, which I’m not planning to push now.

  • save a Git message in a java variable
  • How to push a single file change to two branches using tortoise git?
  • Is git only good for text files/source code?
  • Git: tell a remote repository to check itself out locally
  • git clean exclude with regex
  • Why can't I push to this bare repository?
  • Is it possible to do the rebase without having to deal with commit C.

    Thanks

  • What are the difference between these 3 .gitignore entries?
  • Git: Pulling a rebased branch
  • Git ignoring icon files because of Icon? rule
  • SSH hangs at “SSH2_MSG_SERVICE_ACCEPT received” or “SSH2_MSG_NEWKEYS received”
  • Git Daemon Hang SO_KEEPALIVE
  • how to alias git flow hotfix finish
  • 2 Solutions collect form web for “Git rebase –merge with only some of the commits”

    Saving before the rebase

    The easiest way to save the commit so you can postpone dealing with the conflicts would be to tag it so you have a reference to the commit later:

    $ git tag save-commitC <sha1>
    

    Rebasing without commit C

    After you’ve saved a reference, rebase without the commit:

    $ git rebase --interactive --merge FETCH_HEAD
    

    It should open your editor to file looking like this:

    pick <sha1> <message>
    pick <sha1> <message>
    pick <sha1> <message>
    ...
    

    To delete commit C from this branch’s history, simply remove or comment out the commit’s pick <sha1> <message> line.

    Note that commits are listed in reverse order, with the oldest commits first, the most recent ones last. The first commit on the list should be the first commit that is not an ancestor of FETCH_HEAD.

    Once you’ve rebased without C, go ahead and push:

    $ git push origin master
    

    Reapplying the commit

    When you’re ready to apply it on the rebased branch:

    $ git cherry-pick save-commitC
       # resolve merge conflicts
    $ git commit
    $ git tag -d save-commitC
    

    You could reset to commit b, then stash your changes, push, and then reapply your stash.

    git reset HEAD~1
    git stash
    (rebasing or whatever other intermediate steps required go here)
    git push
    git stash pop
    
    Git Baby is a git and github fan, let's start git clone.