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 😉

Leave a Reply

Your email address will not be published. Required fields are marked *