How to undo the last commit in Git?

Hi, I'm Melvin George! ๐๏ธ. A web developer and a blogger.
Iโve written code for Mozilla, Qiskit, and an active contributor to many frontend open-source projects that are being used by millions of people around the world. ๐
I love JavaScript, Rust, React.js, and many new exciting technologies that help society to find a solution to an existing problem ๐.
Come check out my blog to see more of software development posts on these technologies. ๐ฆ
Originally Published Here ๐!
To undo the last commit in Git, you can use the git reset command.
You have 2 ways to undo the last commit:
- The first is the
git reset --soft HEAD~1
this command will undo the last commit. For most cases, this command can be used and safe to use. This command will also make sure to preserve the changes in uncommitted files.
- The second one is the
git reset --hard HEAD~1
Will also undo the last commit but will not preserve the changes to uncommitted files and resets everything. Be cautious when using the above command.




