Skip to content
Home Tutorials Roadmaps Courses Classroom Training Blog
Log in Join free
Git Beginner Free

Undoing Changes

Lesson 4 of 17 · Stashing & Undoing 24%
1. Getting Started
What is Git?
2. Branching & Merging
Branches & Merging
3. Stashing & Undoing
Git Stash Undoing Changes
5. Tags & Releases
Git Tags
6. Git Hooks & Config
Git Hooks Git Configuration
9. Submodules & Subtree
Git Submodules
10. GitHub Actions
GitHub Actions CI/CD
11. Git Worktrees
Git Worktrees

Git provides several ways to undo changes: checkout, reset, and revert.

Syntax

GIT
git checkout -- file.txt
git reset HEAD file.txt
git reset --soft HEAD~1
git revert HEAD
Undoing Changes
BASH
# Undo working changes
git checkout -- filename.txt
git restore filename.txt

# Unstage file
git reset HEAD filename.txt

# Amend last commit
git commit --amend -m "Updated message"

# Revert commit (creates new commit)
git revert abc1234

Practice

1
Exercise

Practice this concept.

Answer
Run the commands as shown above.

Quick Quiz

1

What did you learn?

This covers the basics.

Choose an answer to continue.

Interview Questions

It is a fundamental Git feature.

Up next

Working with Remotes

Lesson 5 of 17 · Remote Repositories