Was your current merge to production buggy?
Do you want to go back to the previous version of code without reverting the changes?
Switching to old version without Reverting
git checkout <commit id of the previous/old merge>
git checkout 893faa2a
What this does is that it shifts the HEAD to the old version of the code stored in git without making any changes to the commit history.
The HEAD is in detached mode so you can make changes and commit them but they will not affect the branch
To keep the changes and commits, you can create a new branch by :
git switch -c <new-branch-name>
This look cool but, the problem arises when you have to remember the commit ids for the merge commits and it is a tedious task.
Using Tags in Git
Git has a special feature of tagging the commits.
We can use this feature to tag our commits/merge commits as a version of the code.
To add a tag to the current commit
git tag <name-of-the-tag>
git tag v1.4.0
To add a tag to an old commit
git tag <name-of-the-tag> <commit-id>
git tag v1.3.0 893faa2a
To list all tags
We can also list all the available tags in ascending order.
git tag
Now that we have tagged our commits we can easily remember their names and checkout to them whenever we want without reverting the code.
Switching to old version without Reverting using Tags
git checkout <tag-name>
git checkout v1.3.0
For More Info Visit
Top comments (0)