Showing posts with label GIT reset. Show all posts
Showing posts with label GIT reset. Show all posts

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.

GIT remove last commit or go to previous commit

 If you commit the changes by mistake and want to remove that commit or want to go to the last commit then here are some simple commands.


In my example, I have added comments in the code and committed it.

Step 1: Run the command on Command Prompt / Terminal


    git log --oneline




It will display all the recent commits. In my example, I have recently committed "7897e22". Not, I want to go to the previous commits.


Step 2: Run the next command
    

            git reset head~1  (or)

            git reset 0e18a7c


Either you can go to the previous commit by (head~1) or you can specify the Id by checking from the git log.


You can use any one of the above commands.


Step 3: Once you run this command, you can see your changes in the Git Changes. If you want to delete all the changes then You can run the reset hard command. Please run this command carefully. If will remove all the recent changes.

       git reset --hard


Now, if you will check the git log again, you can see recent commit has been removed from the log.






If you only want to revert the changes and do not want to delete them from the log then you can follow the below article.
https://setiasunny.blogspot.com/2023/01/revert-git-changes-through-terminal.html

I hope you like the article. Thank you for reading this.




How to get PowerBI Embed Token

 Here's a step-by-step guide to help you through the process. Step 1: Register Your App in Azure 1. Go to Azure Portal → App registratio...