About this question
How do you discard unstaged changes in Git? What commands can you use to safely remove modifications and restore files to their last committed state?
How do you discard unstaged changes in Git? What commands can you use to safely remove modifications and restore files to their last committed state?
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask DevOps Expert
Answered on Aug 26, 2025
When working with Git, it’s common to make edits you later decide not to keep. This raises the question: “How do I discard unstaged changes in Git?” Unstaged changes are modifications in your working directory that haven’t been added to the staging area yet. Fortunately, Git offers simple ways to remove them.
Discard Changes in a Single File
If you only want to discard changes in one file:
git checkout -- filename
Or, in modern Git versions:
git restore filename
This reverts the file back to its last committed version.
Discard All Unstaged Changes
To remove changes across your entire working directory:
git restore .
Or using the older command:
git checkout -- .
Discard Untracked Files Too
If you also want to delete new, untracked files (not yet staged or committed):
git clean -fd
Be careful—this permanently deletes untracked files and directories.
Safety Tip:
Always double-check before discarding, as these changes cannot be recovered unless backed up or stashed. If you’re unsure, consider using:
git stash
This temporarily saves your changes without committing them.
Key Takeaway:
Use git restore (or git checkout -- in older versions) to discard unstaged changes safely. For complete cleanup, combine it with git clean—but use caution to avoid losing important files.
Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Most-read guides across JanBask
Common DevOps interview questions, answered
Guides, tips and career advice on DevOps from JanBask experts.
DevOps How to Become a DevOps Engineers: Learning Path, Critical skills & More
Looking for answer to how to become a DevOps engineer in 2025? Here is the detailed article about DevOps career path, DevOps…
DevOps Top 50+ Jenkins Interview Questions And Answers For 2025
Here are the Top 50 Jenkins interview questions frequently asked in top MNCs which will help you land an ideal job! These…
DevOps Best 37 DevOps Tools To Learn And Master In 2025: Docker, Git & More
Want to know what are Devops tools and their uses? Or looking for the best DevOps list for automation, monitoring, & development?…
DevOps DevOps Engineer Job Description: Roles and Responsibilities [2025 Updated]
Discover the essential roles and responsibilities of a DevOps Engineer by exploring the detailed DevOps job description, and…