git revert from previous commit

There are several ways you can revert a previous git commit and it depends on your requirement.

  • Temporarily switch to a previous commit – git checkout <commit_sha>
  • Create a branch from previous commit – git checkout -b <new_branch_name> <commit_sha>
  • Revert to previous commit keeping history – git revert <commit_sha>
  • Revert to previous commit discarding history – git reset –hard <commit_sha>

Example:

Leave a Reply