Skip to content
Home Tutorials Roadmaps Courses
Log in Join free
Tutorials Git Undoing Changes
Git Beginner FREE

Undoing Changes

Lesson 2 of 17 Beginner Interactive

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.

Interview Questions

It is a fundamental Git feature.