Let say, you have Committed some change and pushed the changes to your git repo.
But now you want to revert/remove the changes from your git repo as well as from your local machine, then git revert can help you.
Note-> This command won't remove the commit from commit history, it only revert the change from files.
As per Google
The git revert command is a forward-moving undo operation that offers a safe method of undoing changes. Instead of deleting or orphaning commits in the commit history, a revert will create a new commit that inverses the changes specified
to read from git documentation https://git-scm.com/docs/git-revert.
Step-1
We need commit id to revert the specific commit. So to get commit id enter below command in your code editor terminal or command prompt.
git log
this will show list of commit with commit id, author, Date and commit Name
so the top one will show the latest commit. so copy the id from the log and close the process by pressing semicolon + q button.
Step-2
Now lets use git revert command.
git revert <commit-id>
and press Enter
.
after enter we will see screen like this :
you can see your commit name and commit id with files that have changes.
Step-3
So now we have to exit vim and commit the changes.
To do that press.
-
Ctrl+C
after pressing Ctrl+C
it will ask to Type: qa and press enter
.
2.Then type qa
and press Enter
.
And you will exit of vim ui. and screen will look like this.
And you will see that you have created one commit and that is the reverted commit.
Step-4
Now we have to push the reverted commit by using git push.
git push
and Done.
if you see the commit list you will see you have added one new commit starting with Revert
key.
That's all guys.. And All the best.
Top comments (0)