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.
Is it possible to do the rebase without having to deal with commit C.
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
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