educative.io

Reset --hard git commands

Hello, i didnt understant this comment, could some one explain me with one example because i don’t see the any different before and after when using state . thanks

" ```
git reset --hard HEAD~1



----
Course: https://www.educative.io/collection/10370001/6603873985757184
Lesson: https://www.educative.io/collection/page/10370001/6603873985757184/5586706990891008

Hi @ayman,
Let’s say you have a document example.txt, and you made some changes to it. You saved those changes, but then you realize that the changes you made are not what you wanted.

If you want to go back to the version of the document before you made those changes, you could use a command similar to git reset --hard HEAD~1 in Git.

  • The HEAD refers to the latest version of the document, and the ~1 means to go back one version.
  • The --hard option means to discard any changes you made since the previous version.

So, if you run the command git reset --hard HEAD~1, Git will discard any changes you made since the previous version of the document and take you back to that previous version.

I hope this helps. :slight_smile:

very clear, Thank you very much

1 Like