Fixing Mistakes
The most common reaction to making a mistake in Git is to panic. What if you have just lost all your work? Worse, what if you have broken the master branch?
This chapter will review a number of common Git mistakes and how to fix them. The first rule, of course, is stay calm, or as Douglas Adams said, Don't Panic!
The problems we'll review are:
- You wrote the wrong message in a commit.
- You forgot to add changed files from your last commit.
- Problems with the order of commits or their messages.
- You need to undo changes made in a commit.
- You misnamed your branch.
- You committed to the wrong branch.
- You trashed a file in a previous commit.
- You messed up the remote by pushing a broken branch.
To see the answers at work, let's mirror Panofy
into ErrorsDemo
. Here are the steps we'll be doing:
- On the remote, create
ErrorsDemo
and get its URL. - Go to the local branch you want...