Followers

Git revert command-Example

  git revert command will undo the changes for a particular commit and unlike git reset command it will not delete the commit details. Prere...

 git revert command will undo the changes for a particular commit and unlike git reset command it will not delete the commit details.

Prerequisite:- A local repo where you are running the below commands.

Step1 :-> Create a file called package.json and commit the changes into your local repo.

              touch package.json

              git add package.json

              git commit -m "package.json file is added"

Step2 :-> Modify package.json file and commit it again

              echo "{ course: devops, batch: freshers }" >> package.json

              git add package.json

             git commit -m "package.json file is modified"

Step3:- Verify the git logs

            git log --oneline

     In my case the commits looks like below

753e97d (HEAD -> master) package.json file is modified

0c94fe2 package.json file is added


Step4: - Revert back the changes related to the modification of the package.json file.

              git revert 753e97d

Step5:- Check git log entry, the commit should not be deleted and there must be a new commit that is related to revert changes.package.json file should be empty.

             git log --oneline

             cat package.json

Below are my git log details.

466a416 (HEAD -> master) Revert "package.json file is modified"

753e97d package.json file is modified

0c94fe2 package.json file is added


Step6:- Bring back the changes of package.json file.

           git revert 466a416

            git log --oneline

           cat package.json



COMMENTS

Name

Ansible,6,AWS,1,Azure DevOps,1,Containerization with docker,2,DevOps,2,Docker Quiz,1,Docker Swarm,1,DockerCompose,1,ELK,2,git,2,Jira,1,Kubernetes,1,Kubernetes Quiz,5,SAST DAST Security Testing,1,SDLC Quiz,3,SonarQube,3,Splunk,2,vagrant kubernetes,1,YAML Basics,1,
ltr
item
DevOpsWorld: Git revert command-Example
Git revert command-Example
DevOpsWorld
https://www.devopsworld.co.in/2022/02/git-revert-command-example.html
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/2022/02/git-revert-command-example.html
true
5997357714110665304
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content