Problem:
Sometimes, we commit code mistakenly in the branch and we want to remove the mistakenly committed code.
Solution:
We can use the git reset command to reset our changes to commit id up to which we want to revert our code changes using below three steps (git commands)-
git log –oneline
Use this command to get all the commits done so far along with commit id
git reset CommitId –hard
Use this command to reset your changes to the commit you want to keep. Please remember that all following commits after this commit will be lost. Commit Id you can get using above command i.e
git log –oneline
git push -f
Your changes will not reflect until and unless you execute this command. You need to provide this command after above command i.e git reset commitId –hard.
Example Screenshot-
