DEV Community

Cover image for Git - How to fix a bad commit

Git - How to fix a bad commit

Guillermo Verón on April 24, 2021

Oh no, this commit is a mess! 🤦‍♂️ We all have a bad day sometimes. We can forget to include a file, leave some comments, or a merge didn't go as ...
Collapse
 
qwby profile image
Dominik Halfkann • Edited

Those are some great tips! I always loved this site called „Oh Sh*t, git“ because it has a pretty elaborative list of what can go wrong and how to fix it: ohshitgit.com/

Collapse
 
guivern profile image
Guillermo Verón • Edited

What a great resource! Thanks a lot for sharing it. 🚀

Collapse
 
markoshiva profile image
Marko Shiva

just learn it like any other language or a tool in toolchain.
Like cmake or makefile syntax... :)
Its not hard especially if you do not mind studying how it is implemented there are nice courses on the topic.

Collapse
 
pavelee profile image
Paweł Ciosek

thanks, really useful. It's funny that most dev use git, but not many know stuff you mentioned here.

Collapse
 
guivern profile image
Guillermo Verón • Edited

Thanks to you, @pavelee ! 🙏🏻️

Collapse
 
pichaya07 profile image
Pich Chaya

Thank you for useful tips

Collapse
 
guivern profile image
Guillermo Verón

Thank you 🙌

Collapse
 
kayodeadechinan profile image
Kayode Adechinan

great tips, thanks

Collapse
 
guivern profile image
Guillermo Verón

Thank you! 🙌

Collapse
 
khrisl33t profile image
kHRISl33t • Edited

Using reflog can also be helpful to see what you did on your local. :)

Collapse
 
guivern profile image
Guillermo Verón

Thanks for mentioning it! It's very useful in figuring out what happened

Collapse
 
alekseiberezkin profile image
Aleksei Berezkin

Thanks for not mentioning force push 😉 Worked at project where lead used it routinely, and that was very frustrating

Collapse
 
guivern profile image
Guillermo Verón

Thanks, @alekseiberezkin ! I can't imagine how frustrating it was. 🤦🏻‍♂️️

Collapse
 
jace profile image
Jace Chou

Useful tips

Collapse
 
guivern profile image
Guillermo Verón

Thank you, @mrzhouzh ! 🙏🏻️

Collapse
 
bhupesh profile image
Bhupesh Varshney 👾

Wrote this script to undo your last git f**k up (still in WIP for a stable release)
Might help someone :)

GitHub logo Bhupesh-V / ugit

🚨️ ugit helps you undo your last git command with grace. Your damage control git buddy

ugit

ugit logo

Undo your last oopsie 🙈️ in git without much effort

License: MIT Issues Twitter: bhupeshimself ugit demo gid

Why ugit

  • You did an accidental git command you didn't want to.
  • You don't want to waste your time searching on how to undo ...

What's in the box

ugit supports undoing following operations, some are a WIP. If you know of any operation that can be undone and is not in the list, make sure to send a quick PR 💛️

  • Undo git commit
  • Undo git add
  • Undo git push
  • Undo git branch -D (branch delete)
  • Undo git pull
  • Undo git reset
  • Undo git tag -d (tag delete)
  • Undo git stash apply
  • Undo git stash pop/drop/clear
  • Undo accidental file delete (Restore a deleted file after a commit)
  • Undo (Restore) a file to a previous version
  • Undo git merge
  • Undo git tag (rename a tag)
  • Undo git rebase
  • Undo git cherry-pick
  • Undo git worktree remove (recover deleted work-tree)

Installation




Collapse
 
guivern profile image
Guillermo Verón

Wow! Great job! 🤯️

Collapse
 
lelepg profile image
Letícia Pegoraro Garcez

Wow, that's super useful. I have to say I LOVE git, but I don't know as much as I'd like on how to use it properly haha

Collapse
 
guivern profile image
Guillermo Verón • Edited

Thanks a lot @lelepg , Git is hugeee!

Collapse
 
a2ramu profile image
ramu

This is very useful

Collapse
 
guivern profile image
Guillermo Verón

Thank you 🙌

Collapse
 
sohamraje137 profile image
Soham Patil

git rebase -i Head~x

This works to delete the commit history and rebase your branch on any commit