A few days back, I had a strange issue, well more of a weird server setup. I was working on a new clients server, and they had this wired setup with half of the code running as
root and half as a different user, all permissions were f!!cked up and the client didn't want me to change anything because the setup was ancient and any changes could potentially break the system.
In all that mess, I had to make some test changes right on the server, but when I tried to reset them, they just were not budging, no matter what way I tried, nothing seemed to work. I spent about 2 hours to get rid of everything I did to get previous code back, but nothing was going my way, and after much research, I found out something that worked like a charm:
git checkout HEAD .
What it does is checks out the most recent commit, and revert's back everything to it. Now, there are several ways of doing this same thing, and I did try several of them, but this was the one that worked. So for me, this is what I will use to discard the changes when discarding is not working.
PS: I had to run it with
sudoto make it work...