Uh oh. You just accidentally merged your files to the master branch when you meant to merge them to the staging branch. Now what?
Almost everyone who uses Git makes a mistake at some point. Whether it's merging the wrong files, deleting the wrong branch, or something worse, it's important to know how to undo mistakes with Git.
We've released a crash course on the freeCodeCamp.org YouTube channel that will teach you 17 different ways to undo mistakes in Git.
Tobias Günther developed this course. Tobias has been working with Git for many years. He even helps create Tower, which is a popular Git GUI client.
Many developers are not aware of all the ways that they can use Git to undo mistakes. This course will teach you what Git can do and how Git does it.
The first half of the course includes more common cases that are easier to recover from. The second half teaches more complicated mistakes to fix. But it is possible to undo almost all mistakes in Git.
Here are the topics covered in this course:
- Using Git as a safety net
- Discarding all local changes in a file
- Restoring deleted files
- Discarding chunks / lines in a file
- Discarding all local changes
- Fixing the last commit
- What "rewriting history" means
- Reverting a commit in the middle
- Resetting to an old revision
- Resetting a file to an old revision
- The Reflog
- Recovering deleted commits
- Recovering deleted branches
- Moving a commit to a new branch
- Moving a commit to a different branch
- Interactive Rebase: an overview of what you can do
- Interactive Rebase: how it works in general
- Editing old commit messages with Interactive Rebase
- Deleting commits with Interactive Rebase
- Squashing multiple commits into one with Interactive Rebase
- Adding changes to an old commit with Interactive Rebase
- Splitting/editing an old commit with Interactive Rebase
Watch the full course on the freeCodeCamp.org YouTube channel (1-hour watch).