Monday 2 January 2023

Revert Git Changes Through Terminal / Command Prompt

 If you accidentally commit your code then don't worry you can revert your changes with a few commands. you can easily go to your last commit. Let's learn


Here is my code below. I have added one comment below in one of the files and I'll commit that.







I am saving that file with the below comment. Once its saved then let's run few commands.













1. Let's run the first command on the cmd prompt/terminal

 git log











It will give you the commit Id as shown in the snapshot below. Now we need to revert that changes.


2.  Copy the commit Id and run the second command.

git revert 59186cf31db4c520a6cf68343fb55843d0a369b8


You can see the comment has been removed from the code







3. Git changes will show you revert changes. You need to commit to that and that's it.
















If you permanently delete the changes and remove them from history as well then follow the next article.
https://setiasunny.blogspot.com/2023/01/git-remove-last-commit-or-go-to.html


Hope you will like the article.

No comments:

Post a Comment

How to find the reason of HTTP Error 500.30 - ASP.NET Core app failed to start in Azure App Service

HTTP Error 500.30 - The ASP.NET Core app failed to start If your web app is throwing an error HTTP error 500.30 then how to find the root ca...