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)通过简单的剪切粘贴,按照您的选择重新排序提交。假设新的顺序是:
pick 9781434 commitE
pick c3d4961 commitC
pick 4791291 commitA
pick aa1cefc commitD
pick a2bdfbd commitB
在编辑器中进行这些更改,然后按下 ctrl+O(写出)。
或者您也可以使用
git rebase -i HEAD~<commitNumber>
您可以通过以下方式检查新的序列:
git log
3) 现在使用
git push <remoteName> <commit SHA>:<remoteBranchName>
如果远程(origin)只有一个分支并且本地(master)也只有一个分支,那么只需使用以下命令:
git push <commit SHA>
git push aa1cefc
这将推送提交B和提交D。
master~3
。任何涉及所需“到达”提交的参考都是有效的,例如HEAD~3
或HEAD~~~
,或特定的 SHA 或标记,该标记标记了该提交。 - Kazgit push
命令之前,你应该始终小心并仔细检查你的命令...) - nofinatorgit push origin tocommit:newbramch
。 - Ryan Graham