Git reverting to previous commits on local and remote repositories

Tags in version control systems can be used to keep track of different development versions. This article will show you how to revert back to previous tagged versions, and how to update the remote repository with the changes.

Add Tag

To add a tag to any commit.

git tag v0.0.1

Note: Git tags have to be unique.

Revert back to tagged commit

To change the local repository back to any tagged commit.

git reset --hard v0.0.1

Note: If want to just preview the tagged version, use the checkout command but make sure you checkout back to the master when done.

Force remote repository to reverted changes

If you try and push these changes to a remote repository, it fail to push the changes. If you dont want to merge the existing working repository with the tagged one, force the push with the following code.

git push --force origin

Liked this article? help spread the word.