How to tag an existing commit

Git introduction #

Git is a version control system used for tracking changes in computer files. It is generally used for source code management in software development. Git is used to tracking changes in the source code. The distributed version control tool is used for source code management.

The basic Git workflow goes something like this:

  1. You modify files in your working tree.
  2. You selectively stage just those changes you want to be part of your next commit, which adds only those changes to the staging area.
  3. You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.

Steps for tagging a git commit #

1. Open command line or terminal depending on your operating system

2. Find the commit id that you want to tag.

This can be done easily by finding the commit by going to your repo source control. A commit generally looks like this:

git commit

Or you can also use git cli to see all your commits which will also show the commit ids:

git log --oneline

The output will be something like this, the red box contains the commit id in our example:

    3. Copy the whole commit id or just first 7 letters in case of complete id, both work fine

    4. Tag a commit

    To add a tag with message, run:

    git tag -a v4 9fdf736 -m "Updated environment sdk version"

    To add a tag without message, simply run:

    git tag v4 9fdf736

    Note: If you don’t write any commit id, the last commit will be tagged

    5. Push tag

    To push a single tag, run:

    git push origin v4

    Or to push all tags in one command, run:

    git push origin --tags

    That’s it! You have successfully tagged a git commit.

    Powered by BetterDocs

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Scroll to Top