12 Ways to Undo Mistakes with Git - Part 2
Tags: github, git, webdev
Published: 2020-10-06 17:26:30

Accidentally deleting files... Making typos in your commit messages... Committing on the wrong branch... a lot of mistakes happen when humans write code! But do not despair: Git offers countless tools to undo and recover from small and big mishaps.

In this second part, you'll find another set of 6 short & handy videos that help you undo mistakes with Git! _([Take a look at part 1](https://dev.to/gittower/12-ways-to-undo-mistakes-with-git-part-1-4bmn) if you missed it!)_

---

# Resetting a File to an Old Revision
**Apply in cases of:** _"Yikes! 🤔 I know this file was correct sometime!"_

**Disaster summary:** Not everything was better in the old days! Just this one particular file, that you now long to restore from a previous revision. Here's how!

{% youtube PEXPbscUle4 %}


# Recovering Deleted Commits
**Apply in cases of:** _"Sweet baby Jesus! 😱 Did I just delete the wrong commits?!!"_

**Disaster summary:** Using "git reset" is a wonderful way to get rid of some unwanted commits. But it's also a wonderful way to get yourself into trouble - if you got rid of the wrong commits! But chin up! You can undo even that!

{% youtube 1NpZKyLENoc %}


# Moving a Commit to a New Branch
**Apply in cases of:** _"Damn it! 😣 I should have created a new branch before committing!"_

**Disaster summary:** You've worked busily on a new feature and solemnly made the first commit - although you haven't created a separate feature branch for it. Let's get that new feature commit off of the "master" branch and move it to its own feature branch!

{% youtube yOJ94iIOg9g %}


# Editing Old Commit Messages
**Apply in cases of:** _"Christ on a cracker! 😱 Did I write this commit message?!"_

**Disaster summary:** Sometimes you hit RETURN and notice instantly that you just made a typo in your commit message. No problem: Git's "amend" feature is here to help! Other times, however, it takes days and weeks before you notice your spelling mistakes - and yet there's still a way to save your good reputation!

{% youtube UOVSZEHUHFo %}


# Deleting Old Commits
**Apply in cases of:** _"Knock me over with a feather! 🤔 Did I create that commit?!"_

**Disaster summary:** Buried deep inside your commit history, there's a commit that just shouldn't be there. Let's make it look like it never happened!

{% youtube JI8jxrvMWSI %}


# Squashing Multiple Commits Into One
**Apply in cases of:** _"Holy cow! 🐮 Why did I create so many commits??"_

**Disaster summary:** Committing in small, granular doses is actually a virtue. But of course there can be "too much of a good thing". If you've overdone it and want to combine multiple commits into one: here's how!

{% youtube -ToF4P7AjBU %}

---

It's probably quite obvious by now: **Git is an excellent safety net!** You can undo and repair almost anything! The tricky part is mostly just knowing the corresponding workflows and commands.

To help your memory, you can [download all 12 cases + **5 extra episodes and 1 cheat sheet**](https://www.git-tower.com/learn/git/first-aid-kit?utm_source=devto&utm_medium=guestpost&utm_campaign=12-ways-to-undo-mistakes) as part of my free ["First Aid Kit for Git"](https://www.git-tower.com/learn/git/first-aid-kit?utm_source=devto&utm_medium=guestpost&utm_campaign=12-ways-to-undo-mistakes).

[![first-aid-kit](https://dev-to-uploads.s3.amazonaws.com/i/f9gfafqhh1d8rqgznrjj.png)](https://www.git-tower.com/learn/git/first-aid-kit?utm_source=devto&utm_medium=guestpost&utm_campaign=12-ways-to-undo-mistakes)

---

## About the Author
[Tobias Günther](https://twitter.com/gntr) is the CEO of [Tower](https://www.git-tower.com/?utm_source=devto&utm_medium=guestpost&utm_campaign=12-ways-to-undo-mistakes), the popular Git desktop client that helps more than 100,000 developers around the world to be more productive with Git.