This guide will elaborate on the procedure to tag an older commit in the Git repository.
How to Tag an Existing Commit in Git?
Check out the below-stated procedure to tag an old commit in the Git repository:
- Go to the particular Git repository.
- Check the log history of the current working Git repository.
- Copy the required commit SHA hash.
- View the list of the existing Git tags.
- Use the “$ git commit -a <tag> -m <commit-message>” command.
Step 1: Move to Required Git Repository
First, navigate to the desired local repository by running the “cd” command along with its path:
Step 2: Check Repository Reference Log History
Then, view the reference commit history of the particular repository with the help of the “git log .” command:
As a result, the above-stated command will display all the log history. Copy the SHA hash of the desired commit you want to tag. For instance, we have copied the “a8d5313” commit Id of the “deleted” commit message:
Step 3: Checkout to Commit SHA Hash
Next, execute the “git checkout” command along with the copied commit SHA hash and switch to it:
Step 4: View Existing Git Tag List
Run the “git tag” command to display the list of existing Git tags:
Step 5: Tag Desired Commit
After that, tag the selected old commit by running the “git tag” command along with the tag and commit message:
In the above-stated command:
- “-a” flag is used to track all the added changes automatically.
- “v2.2” is the new Git tag.
- “-m” option adds a commit message to the repository.
Step 6: Check Log History
Lastly, check the log of a particular Git repository by running the “git log .” command:
That’s all! We have explained the procedure to tag an older commit in the Git repository.
Conclusion
To tag an old commit in the Git repository, first, move to the Git particular repository, check the log history of the current working Git repository, and copy the required commit SHA hash. After that, display the existing Git tags. Lastly, run the “$ git commit -a <tag> -m <commit-message>” command. This guide explained the method to tag an older commit in the Git repository.