DEV Community

Dedar Alam
Dedar Alam

Posted on

How to revert git commit easily

First check the git log by running the command git log --oneline

git log screen shot

Here you can see last six commit of this git repository.

add hello file this commit for add the hello file
and after this commit last five commit i add five line

Now i want to revent the line 5 commit.
I add this line on 1009bb3 add line 5 commit.
here
1009bb3 - commit hash
add line 5 - commit message

so next step is run revert command git revert --no-commit <commit hash>
here our revert command is git revert --no-commit 1009bb3

revert commit run screen shot

After run the revert commit, line 6 is gone. now i have to commit the revert commit changes

commit all the revert commit changes screen shot

here commit all the changes after run revert commit

after revert commit git log screen shot

now time to check git log. now here one new commit add Revert "add line 5"


Reference Source

Top comments (0)