How to discard the changes I don't commit?
I don’t know what happened but I messed up the Git repo again. So all was OK , it was compiling fine. Not compiling now. I had made some changes, not committed any. When I do repo diff I see the changes I made and some weird changes have come into the code. I don’t know! Lot of them. So now I think inorder to fix this and keep the changes I deliberately made and the changes that appear from no where. I will do git add the changes I made and I want to discard all the changes that otherwise appear. How to do this ?
git add filepath
And how to discard what I don’t want to add and commit?
2 Solutions collect form web for “How to discard the changes I don't commit?”
You can do the following steps:
git addto add the changes you want to keep.
git committhose changes to the repository.
git reset --hard HEADto throw away the rest of the changes.
Note that step 3 is destructive and you can’t use Git to recover those changes. Make a backup first if you’re unsure.
If you are using the GitHub GUI (Windows or Mac) and are not worried about losing the local changes on your computer but just need to get the latest version from GitHub:
Simply use “discard changes” before attempting to sync. This can be done either for a specific file:
or for all files:
It reverts all selected files to the last version committed to the repo.