Change second and last action

If you find an error in your last commit, you can simply confirm the last commit with

git commit --amend

But if you have committed yet another commit, how do you resubmit the commit before that?


Note: I assume that you know that you should only use it --amendif you are sure that no other developer has used your upstream file.

+4
source share
2 answers
  • fix the fix with

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

    (commit message is not important, it will be obsolete after completion)

  • :
    HEAD , , , :

    git rebase -i HEAD~3

    3 :

     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
     # …
    

    , :

     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
     # …
    
  • git log HEAD~3
  • +,

    git push origin +branchname
+4

@aragaer :

git commit -a --fixup=HEAD^ #(or whatever commit to be fixed)

git rebase -i HEAD~3

, , git .

+1

Source: https://habr.com/ru/post/1547536/


All Articles