Reputation: 6568
I have made multiple commits but don't want all commits to be pushed for now. Is there a way to push only those commits which I want?
Thanks
Upvotes: 4
Views: 162
Reputation: 393934
You have two options,
Say, you want to include 3 out of five most recent commits:
git rebase -i HEAD~5 # reorder the lines in the text editor,
# leave the 'private' commits at the end
git push origin HEAD~2:master # push all but the last two
This involves a temporary branch and is a lot more work
git checkout -b temp HEAD~5
git cherrypick <hash1>
git cherrypick <hash2>
git cherrypick <hash3>
git push origin master
--cherry-pick
or --cherry-mark options
with git log
to see the actual differences between refs (git log --cherry-pick --oneline master...origin/master
)Upvotes: 5
Reputation: 9318
This command can help:
$ git push origin <thelonghash>:master
But if you have commits A->B->C->D
and do git push origin C:master
the commits A,B,
and C
will be pushed to origin. So if you need push only C
you need to use git rebase -i
to
rearrange the commits so that C
is earliest.
Upvotes: 1