Creating New Git Tag Based on Previous Commit

Preface

Simple way to create new tag/release based on previous commit, in case you forgot to create a tag/release for the previous version of code.

Prerequisite

  • Access to your repository.

Procedure

Move into your repo directory in your local:

cd /path/to/your/repo

Find the hash of the commit you want from git log:

git log

Or if you know your commit message, you can use grep:

git log | grep "<YOUR-COMMIT-MESSAGE>"

Create the tag for the commit:

git tag <TAG-NAME> <COMMIT-HASH>

Push into remote repo:

git push origin <TAG-NAME>

Conclusion

Congrats, now you’ve saved your previous code state into a proper tag. If you’re using Github, now you can use that tag for a release.