reset vs revert in git

In this article, we are going to see the difference between Git reset and Git revert. As we know that Git revert does not delete the commit from the Git history but creates new commit wherein all changes are reverted from specific commit. Main difference in Git reset and revert is that in Git reset commit history of Git changes as shown in below image. Commits with id C3 and C4 are removed if we execute below command.
 
git reset HEAD^^
Below image shows the sample Git log before executing reset command. Below image shows the sample git log after the git reset command is executed. Notice that last 2 commits have been deleted from git log history.

Hard and Soft reset in Git

 
git reset –hard HEAD~1 – After reset, It removes changes from staging area and working copy.
git reset HEAD~1 – After reset, working tree will not be affected. But changes in staging area will be removed.
git reset –soft HEAD~1 – After reset, working tree and index (staging area) is not affected.
git reset –hard origin/master : resets the local branch to remote master branch
Here is the output of above example.


Web development and Automation testing

solutions delivered!!