RE: Git: How to discard local changes?

I have made some changes to my local Git repository that I want to discard. What command do I need to use to do this?

Add Comment
2 Answers
To discard all local changes that are not committed in Git, you can use `git reset --hard HEAD` command. This will discard all local changes to the state of the HEAD. If you only want to discard changes to a specific file use `git checkout -- [file]`. Remember though, using these commands will permanently discard your local changes. If you're unsure and want to check which files have changed first, run `git status`. Always make sure you really want to discard changes as this process is not reversible. Take precautions and consider using `git stash` which puts the changes in a separate place, where they can be re-applied or completely discarded later.
Answered on July 11, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.