Added spell.
h3rald h3rald@h3rald.com
Sun, 03 Mar 2024 11:00:12 +0100
1 files changed,
25 insertions(+),
0 deletions(-)
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) +