git命令 - 在推送时过滤提交

ash*_*ai_ 4 git github

我做了多次提交,但不希望现在推送所有提交.有没有办法只推动我想要的那些提交?

谢谢

seh*_*ehe 5

你有两个选择,

变基

比如,您想要包含最近五次提交中的三次:

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
Run Code Online (Sandbox Code Playgroud)

樱桃酱

这涉及一个临时分支,还有很多工作要做

git checkout -b temp HEAD~5
git cherrypick <hash1>
git cherrypick <hash2>
git cherrypick <hash3>
git push origin master
Run Code Online (Sandbox Code Playgroud)

建议

  • 我推荐反对cherrypicking,因为它更多errorprone并且很容易使相同的提交看起来"不相同"
  • 使用--cherry-pick--cherry-mark optionswith git log来查看refs()之间的实际差异git log --cherry-pick --oneline master...origin/master