all repos — h3rald @ a4f29cdf59c7ee6da2580dc338fa18ec45f203c4

The sources of https://h3rald.com

Added spell.
h3rald h3rald@h3rald.com
Sun, 03 Mar 2024 11:00:12 +0100
commit

a4f29cdf59c7ee6da2580dc338fa18ec45f203c4

parent

38b2a8d1b1c1136b0ce79c9d4fdc2dd12d5ba94d

1 files changed, 25 insertions(+), 0 deletions(-)

jump to
A contents/grimoire/remove-last-git-commit.md

@@ -0,0 +1,25 @@

+----- +id: remove-last-git-commit +title: "Remove your last git commit" +subtitle: "Because some time you mess up but notice one second too late" +content-type: spell +----- + +Sometimes you get so much into the flow that you accidentally commit stuff too early, and typically notice right after committing. + +Undoing the last git commit is easy enough, thankfully. If you didn't push already, just run + +```bash +git reset HEAD^ +``` + +If you did push to your remote repository, but hopefully no one else pulled already, you can run the following command after the previous one: + +```bash +git push origin +HEAD +``` + +...which will _rewrite history_, but sometimes that's OK. + +Credits: StackOverflow [#1](https://stackoverflow.com/questions/37420642/how-to-undo-the-last-commit-in-git), [#2](https://stackoverflow.com/questions/8225125/remove-last-commit-from-remote-git-repository) +