Uncommit Git's Last Commit | Undo The Last Commit

Uncommit Git’s Last Commit | Undo The Last Commit

How To uncommit Git Files or Undo The Last Commit. Without any further explanations, let’s have a look into the process to undo the last commit or uncommit Git’s last commit.

Uncommit Git’s Last Commit | How To Undo The Last Commit

At first, you need to do a hard reset as it will delete any new files that have been added to the index and undo any changes made to the file by the last commit. Run the command to perform  a hard reset

git@uncommit /c/repo/reset (main-branch)
$ git reset --hard

One of the interesting features of the hard reset is that files created recently that were never added to the index will remain on the filesystem as they won’t get deleted. If you want to delete the files that were never added to the index then run the following command:

git@uncommit /c/repo/reset
$ git clean -fxd

In this way, you can undo the last commit or uncommit Git’s last commit.

How To Undo The Last Commit

In another method, run the following command to undo the last commit.

git revert <commit hash>
You can get the commit hash from the git log command

Summary: In this way, you undo the last commit in Git. Meanwhile, there is not any word like Uncommit in Git. Let us know if you want to add your opinion or wants to suggest us for the improvement of this article on “How To uncommit Git Files or Undo The Last Commit.”

READ More Relevant Stuff:  How To Install WhatsApp On Ubuntu 22.04 LTS

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply

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