When to Use git reset and git revert

Use git reset when you’re making changes locally and haven’t pushed them yet. It’s handy if you realize you’re working on the wrong branch and want to move your changes to another branch without losing them.

Use git revert when you’ve already pushed your changes to a shared repository. It’s like creating a new commit that undoes the mistakes you made, so you don’t mess up the commit history for others.

How to Back Previous Commit in Git ?

Rolling back to a previous commit in Git is a common task when you want to undo changes or revert to a previous state of your repository. In this article, we will learn the process of how to back previous commit in git.

Backing out of a previous commit in Git involves undoing the changes introduced by one or more commits and returning the repository to a previous state.

There are two ways to back out of a previous commit in Git:

Table of Content

  • Using git reset command
  • Using git revert command

Similar Reads

Using git reset command

Step 1: Open your terminal or command prompt and navigate to empty desktop or any folder...

Using git revert command

Step 1: Open terminal, navigate to preferred folder, create a text file, add some lines and make commit as we did previously....

When to Use git reset and git revert

Use git reset when you’re making changes locally and haven’t pushed them yet. It’s handy if you realize you’re working on the wrong branch and want to move your changes to another branch without losing them....

FAQs

Can git reset be used to undo changes that have been pushed to a remote repository?...