1)如果需要,请使用“ git rebase”对提交进行重新排序。
git rebase -i
该命令将在您的编辑器中显示类似的内容(我正在使用vim)
pick 4791291 commitA
pick a2bdfbd commitB
pick c3d4961 commitC
pick aa1cefc commitD
pick 9781434 commitE
# Rebase ..............
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
^G Get Help ^O WriteOut ^R Read File ^Y Prev Page ^K Cut Text ^C Cur Pos
^X Exit ^J Justify ^W Where Is ^V Next Page ^U UnCut Text ^T To Spell
2)通过简单的剪切粘贴根据您的选择重新排列提交。假设新订单是
选择9781434 commitE
选择c3d4961 commitC
选择4791291 commitA
选择aa1cefc commitD
选择一个a2bdfbd commitB
在编辑器中进行这些更改,然后按ctrl + O(写出)
或者你也可以使用
git rebase -i HEAD~<commitNumber>
您可以使用
git log
3)现在使用
git push <remoteName> <commit SHA>:<remoteBranchName>
如果只有一个分支位于远程(原始),而一个分支位于本地(主),则只需使用
git push <commit SHA>
git push aa1cefc
这将推送commitB和commitD。
master~3。对所需的“最多”提交的任何引用都同样有效,例如HEAD~3或HEAD~~~,特定的SHA或标记该提交的标签。