Undoing things#

Learning Objectives#

After working through this topic, you should be able to:

  • use git checkout to go back to a previous commit without destroying anything

  • use git revert to undo a specific commit

  • use git reset to permanently go back in time

Notes#

While a primary goal of git is to have the ability to go back in time, it actually does not happen too often that you need to undo commits after you made them. Here is an orientation of how often certain things will happen:

Action

Frequency

Undo changes before you committed them (using git reset –hard)

All the time

Browse earlier versions of files on github or via git checkout

Very often

Use git revert to undo a specific commit

Once per year?

Use git reset to undo the last few commits

Once per year?

There are two reasons for this:

  1. As you will see in the next video, we will often work with branches; If stuff does not work out we can simply abandon/delete a branch and there is no need to undo any commits on the main branch

  2. Modifying the commit history becomes harder when you collaborate with other via GitHub. Instead of removing commits you will rather add new commits that undo changes.

Materials#

For this topic we are building on the excellent YouTube playlist by NetNinja

Quiz#