Don’t know how to revoke wrong commits in GIT

Committed the wrong files by mistake?

This article covers how to revoke the wrong commits in GIT.

revoke wrong commits

When we commit and push our code sometimes it is possible that we may have replaced it with the older code or a wrong piece of code in a hurry.

Don’t worry we can ignore the fault change with the new correct code by using the below piece of lines.

Assume we have committed the wrong file and then we realize that is the mistake we have made before giving the push command. If that is the case, revoke the wrong commit in GIT.

We can use the below lines of codes

$ git commit -m "Latest Updates" 
$ git reset HEAD~
change the files and code at this stage 
$ git add .                                    
$ git commit -c ORIG_HEAD                      
$ git push        

Let’s assume we have committed the wrong files to the GIT repository. Now how to deal with such cases,

Type in the below lines of code

$ git commit -m "Latest Updates" 
$ git push
$ git revert commitID from GIT

In the editor, window give wq:! To exit from the popup then

$ git add .                                    
$ git commit  -m  “Pushing the files after revert”                      
$ git push        

The git revert command allows you to undo the changes you have made to a code repository since a specific commit. Instead of deleting a commit, the git revert command identifies the changes between the current commit and a previous commit and creates a new commit to revert those changes.

Leave a Reply