git checkout HEAD filename
In GIT, usually when a commit occurs, HEAD points to the latest commit.
For an example, there is a commit made in a file. You further made some changes. Later at some point, you realize that change is not required anymore. In this case, you need to point the head to the old HEAD. Below command should be used.
git checkout HEAD <<filename>>
In a nutshell β above command is used to discard changes in the working directory
git reset HEAD filename
Imagine you made changes to file1.txt and file2.txt and added to staging area. Further you accidentally made some changes to file3.txt and added to staging area. Later you realize, changes made to file3.txt is unnecessary.
So, in order to remove file3.txt from staging area, use below command
git reset HEAD <<filename>>
basically this command is used to unstage changes from staging area.
Remember, this command only removes file from staging area. The changes you made to the file remains available.
git reset commit_SHA
Imagine if you have made 10 commits on a single file. If in case, if you need to discard all the changes from 6th commit, you would use this command so that all commits from 7th to 10th commit will be removed.
git reset 232bfg2
here 232bfg2 is first 7 characters of git commit SHA