How to reorder last two commits in git?

前端 未结 4 1080
你的背包
你的背包 2021-02-02 07:09

I want to reorder last two commits in git:

right now I have:

$ git log --oneline -4
1e0ecba (HEAD, my-branch) Fix for T255
82d45dc django_extensions
af3953         


        
4条回答
  •  遇见更好的自我
    2021-02-02 07:29

    In general you have to use git rebase --interactive - here is detail answer how to reorder any number of commits:

    But if you want to reorder last two commits you can use this git alias:

    Add to ~/.gitconfig:

    [alias]
        reorder = "!GIT_SEQUENCE_EDITOR=\"sed -i -n 'h;1n;2p;g;p'\" git rebase -i HEAD~2"
    

    and then:

    $ git reorder
    Rebasing(2/2)
    Successfully rebased and updated refs/heads/my-branch.
    

提交回复
热议问题