Amend the second to last commit

  1. commit your fixup with

    git commit -a -m "fix commit (this one will be shifted up one line)"

    (the commit message is not important, it will be obsolete once you are finished)

  2. Now the magic:
    rebase the HEAD to the second last commit but edit the commit message before in that way, that you swap the last and the last but one line in the message editor:

    git rebase -i HEAD~3

    The editor will show the last 3 comits like this:

     pick 2a06f16 this was the last commit
     pick 0dbc5ce the last-but-one commit
     pick 2e30418 fix commit (this one will be shifted up one line)
    
     # Rebase 011f3d0..2e30418 onto 011f3d0
     # …
    

    swap the last two lines so the commit message will look for example like this:

     pick 2a06f16 this was the last commit
     fixup 2e30418 fix commit (this one will be shifted up one line)
     pick 0dbc5ce the last-but-one commit
    
     # Rebase 011f3d0..2e30418 onto 011f3d0
     # …
    
  3. Check your log with

    git log HEAD~3
  4. push the corrected commit-line with + to force a new push to the already existing branch with

    git push origin +branchname

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)