Git – revert or amend last commit

Since we moved from SVN to git in HeiaHeia I had to revert or amend changes I accidentally committed or committed and pushed to git repository. This is not the most common operation, so I have to browse the documentation every time I do that. This is more of a memo to myself, which hopefully will be useful to others too.

Committed some changes, didn’t push them, and need to amend the commit:

git commit --amend -a -m "Commit message"

Committed some changes, pushed them, and need to amend the commit, do the revert operation instead, since someone might’ve already used your changes.

Committed some changes, didn’t push them, and need to undo the commit:

git reset --hard HEAD^

This will just toss away the last commit completely.

Commited some changes, pushed them, and need to undo the commit:

git revert HEAD

This will automatically create a new commit, reverting the changes from the previous


Comments

18 responses to “Git – revert or amend last commit”

  1. […] Continue reading here: Ivan Kuznetsov › Git – revert or amend last commit […]

  2. It was useful to me too, thanks

  3. DavidZoope

    Achetez vos kamagra medicaments: Kamagra Commander maintenant – kamagra pas cher

  4. PeterVof

    pharmacie en ligne sans ordonnance pharmacie en ligne france livraison internationale Pharmacie sans ordonnance pharmafst.shop

  5. Bradleynag

    pharmacies en ligne certifiГ©es: Pharmacies en ligne certifiees – Pharmacie Internationale en ligne pharmafst.com

  6. BillieOxymn

    п»їpharmacie en ligne france: Meilleure pharmacie en ligne – pharmacie en ligne france livraison internationale pharmafst.com

  7. RobertFloob

    http://pharmafst.com/# Pharmacie Internationale en ligne

  8. Bradleynag

    п»їpharmacie en ligne france: Pharmacie en ligne France – pharmacie en ligne fiable pharmafst.com

  9. BillieOxymn

    Pharmacie Internationale en ligne: pharmacie en ligne sans ordonnance – vente de mГ©dicament en ligne pharmafst.com

  10. RobertFloob

    https://kamagraprix.shop/# Kamagra Commander maintenant

  11. Bradleynag

    pharmacie en ligne pas cher: pharmacie en ligne avec ordonnance – trouver un mГ©dicament en pharmacie pharmafst.com

  12. PeterVof

    cialis prix Cialis en ligne cialis prix tadalmed.com

  13. BillieOxymn

    pharmacie en ligne sans ordonnance: Livraison rapide – pharmacie en ligne france livraison internationale pharmafst.com

  14. BernardBroam

    pharmacie en ligne: pharmacie en ligne pas cher – trouver un mГ©dicament en pharmacie pharmafst.com

  15. RobertFloob

    http://pharmafst.com/# vente de mГ©dicament en ligne

  16. Bradleynag

    pharmacie en ligne sans ordonnance: pharmacie en ligne pas cher – pharmacie en ligne pharmafst.com

  17. BillieOxymn

    pharmacie en ligne france fiable: pharmacie en ligne – pharmacie en ligne france livraison internationale pharmafst.com

  18. BernardBroam

    Kamagra Oral Jelly pas cher: Kamagra Oral Jelly pas cher – Kamagra pharmacie en ligne

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.