Reputation: 43
Hi folks I am new developer trying to learn.
I use git desktop where you right click on a file and select discard changes, if you don't want to add that file into commit. It revert it back to its original state.
Now I am working in terminal how can I do that in terminal?
By mistake I added some changes into a file and I don't want to keep those changes. Please help.
Please, I am not an advanced user therefore kindly keep it as simple as possible. I have not made any commit on that machine yet.
I am only interested in I googled it but could not find a simple layman'ish answer.
Upvotes: 0
Views: 2226
Reputation: 24038
You can simply use:
git checkout -- path/to/file
The --
is so that the filename or path cannot be inferred as a branch or remote/branch.
Upvotes: 3
Reputation: 166
There are multiple ways to do it. I will mention the simplest of all. It has 2 step:
Unstage the file to latest/current commit. Only required if the the changes to the file is staged.
git reset HEAD <file>
Undo the file changes.
git checkout <file>
Upvotes: 0
Reputation: 217
You can do this in several ways
git checkout file_path
git stash file_path
git reset --hard HEAD~1
git reset --hard commit_sha
Upvotes: 0