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 коммит
pick c3d4961 commitC
выбор 4791291 commitA
выберите aa1cefc commitD
выберите a2bdfbd commitB
Сделайте эти изменения в вашем редакторе и нажмите ctrl + O (writeOut)
Или вы также можете использовать
git rebase -i HEAD~<commitNumber>
Вы можете проверить новую последовательность с помощью
git log
3) Теперь используйте
git push <remoteName> <commit SHA>:<remoteBranchName>
Если только одна ветвь на удаленной (источник) и одна на локальной (главная), просто используйте
git push <commit SHA>
git push aa1cefc
Это будет выдвигать commitB и commitD.