git TutorialIntroduction Installing Git Understanding Git architecture Initializing the new Git respository Cloning new Git repository .git directory in Git repository Viewing Git configuration First time Git configuration Using SSH keys with Git Checking Git status Adding files into staging area in Git Committing changes to the local repository Ignoring files using .gitignore Viewing the history of commits Viewing the file contents in working directory, staging area and repository Viewing difference between files Viewing the history of files Git revert Git Reset git reflog Creating and switching to new branches in Git Viewing existing branches Merging branches Resolving conflicts Rebase Deleting branches Renaming the branch in Git Push Pull Stashing the changes in Git Tags in Git Patches in Git Creating new repository on GitHub Pushing local repository to remote repository like GitHub IntelliJ IDEA
reset vs revert in gitIn 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.
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.
git reset HEAD^^
Hard and Soft reset in Git
Here is the output of above example.
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
Complex problems, Simple Solutions