git command - filtering commits while pushing
I have made multiple commits but don't want all commits to be pushed for now. Is there a way to push only those comm开发者_Python百科its which I want?
Thanks
You have two options,
rebase
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
cherry pick
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
Recommendations
- I recommend against cherrypicking since it is more errorprone and easily makes identical commits seem 'unidentical'
- use the
--cherry-pick
or--cherry-mark options
withgit log
to see the actual differences between refs (git log --cherry-pick --oneline master...origin/master
)
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.
精彩评论