Home > Tips & Tricks > Undo a last git commit and redo

Undo a last git commit and redo

Git is a software for tracking the changes in any files. And It mostly used for coordinating work among programmers collaboratively developing source code during software development.

And Github where you can store all the changes of files with each commit note. You can use these commit version further and further using git pull, push, fetch, merge etc command.

In this trick, we will learn how you can get back last git commit and redo again with the new changes.

To undo the last git commit and redo, use the below commands:

The above code will undo your last git commit with this command $ git reset HEAD~ and then you can make your changes in the file.

After all the changes, run the $ git add . command to add new these changes in commit and finally commit your original head using $ git commit -c ORIG_HEAD.

Hope this will work for you.

Being Tricky 😉

Photo of author

About Aman Mehra

Hey there! I'm Aman Mehra, a full-stack developer with over six years of hands-on experience in the industry. I've dedicated myself to mastering the ins and outs of PHP, WordPress, ReactJS, NodeJS, and AWS, so you can trust me to handle your web development needs with expertise and finesse. In 2021, I decided to share my knowledge and insights with the world by starting this blog. It's been an incredible journey so far, and I've had the opportunity to learn and grow alongside my readers. Whether you're a seasoned developer or just dipping your toes into the world of web development, I'm here to provide valuable content and solutions to help you succeed. So, stick around, explore the blog, and feel free to reach out if you have any questions or suggestions. Together, let's navigate the exciting world of web development!

Leave a Comment