Git Reset and Git Revert

Git Reset and Git Revert

·

2 min read

Table of contents

Two commonly used tools that git users will encounter are those of git reset and git revert . The benefit of both of these commands is that you can use them to remove or edit changes you’ve made in the code in previous commits. Let us learn this with an example

  1. Add a text file called version01.txt inside the Devops/Git/ with "This is the first feature of our application” written inside. This should be in a branch coming from the master.

  2. Switch to dev branch

    version1.txt should reflect at local repo first followed by Remote repo for review. [Hint use your knowledge of Git push and git pull commands here]

  3. Add a new commit in dev branch after adding below-mentioned content in

    Devops/Git/version01.txt: While writing the file make sure you write these lines

  • 1st line>> This is the bug fix in development branch

  • Commit this with message “ Added feature2 in development branch”

  • 2nd line>> This is gadbad code

  • Commit this with message “ Added feature3 in development branch

  • 3rd line>> This feature will gadbad everything from now.

  • Commit with message “ Added feature4 in development branch

    1. How to use Git revert?

      Git revert is used when you wish to revert to the previous commits . For example to restore the file to a previous version where the content should be “This is the bug fix in development branch” we use git revert

What is the difference between Git revert and Git reset ?

Git reverts creates a new commit with the version that we wish to revert to and all the history in git remains intact whereas Git reset deletes all the previous history

Git revert:

Git reset: