Module 05 of 12

Undoing Changes

Lessons

About This Module

Everyone makes mistakes in Git: committing the wrong file, writing a bad commit message, committing to the wrong branch, or running a command they instantly regret. The good news is that Git almost never truly loses your work. Once you know which tool fits which situation, a mistake is a minor problem instead of a disaster. This module gives you that toolkit, and the confidence to experiment without fear.

You'll discard unwanted edits and unstage files with git restore, fix your last commit with git commit --amend, and learn the three modes of git reset: --soft keeps changes staged, --mixed keeps them in your working directory, and --hard throws them away. You'll learn the key rule: use reset for commits that are still local, and git revert for commits you've already shared, because revert adds a new commit instead of rewriting history. Finally, you'll meet the reflog, Git's safety net, which lets you recover commits and branches you thought were gone.

Watch the lessons in order, then continue on to Remotes & GitHub.

Lessons

4 videos
01

Git Tutorial: Fixing Common Mistakes and Undoing Bad Commits

Corey Schafer works through real-world mistakes: discarding changes, amending the last commit, moving a commit to the right branch with cherry-pick, soft, mixed and hard resets, and safely reverting commits others have already pulled.

02

Git Reset Visualized

A visual walkthrough of git reset: when you might want it, and how its three modes change what happens to your commit history, staging area, and working directory.

03

How to Undo / Revert a Pushed Commit in Git: 2 Ways

The two ways to undo a commit that's already been pushed: git revert for public, shared branches, and git reset for private ones. It also explains how to choose the right one for your situation.

04

Recovering Lost Commits with Git Reflog

How to use git reflog to find commits that seem to have disappeared after a bad reset or a deleted branch, and restore them so no work is ever truly lost.