Tagging an older commit in Git
This article outlines the steps required to tag old commits in Git. We use git tags to mark specific points in our commit history as important.
Typically, a git tag marks a stable release or an important milestone in a project. How do you tag any git commit?
Tagging an older commit in Git
For the sake of simpler context, we will use a hypothetical situation.
Assume that our production code is in a Git repository. We have made several commits to our repository since the beginning of the project.
We want to tag the first commit in our repository and mark it as the latest stable version of our code. How can we do that?
Assuming the following diagram represents our commit history, how do we mark the first commit?
To tag a commit, we use the command with the -a option git tag
. We must also pass the SHA-1 of the commit we want to tag.
In our example, we will run:
$ git tag -a v1.0 9d0a878 -m "Stable"
We pass a message to our tag using the -m flag. We can push the tag to the remote repository as shown in the following image.
$ git push --tags
The above method will create a tag with the current date and time. If you want to create a tag with the commit date and time, follow the steps below.
We first need to move HEAD to the commit we want to tag. We will use git checkout
the command, as shown below.
$ git checkout 9d0a878
To get the date and time of the current commit, we would run:
$ git show --format=%aD | head -1
Mon, 8 Aug 2022 14:30:26 +0300
To tag our commits with the date and time they were made, we will run:
$ GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" \
> git tag -a v1.0 -m"Stable"
We can then push the tag to the remote.
$ git push --tags
Our tag should have the date and time of the commit. Let's confirm our case on GitHub.
In short, you can tag arbitrary commits in Git. We have already discussed how to tag old commits with and without their date and time.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Ignore everything except certain files in Git
Publish Date:2025/04/20 Views:151 Category:OPERATING SYSTEM
-
This article outlines the steps to make Git ignore all but a few files in a Git repository. The .gitignore file is a useful Git utility that allows us to tell Git which files to track and which files not to track. If you want your .gitignor
List all tags in Git
Publish Date:2025/04/20 Views:120 Category:OPERATING SYSTEM
-
This article will teach us how to list all tags in Git. Git is a version control system that tracks changes in project directories using a Git repository. Changes made to files are tracked in a Git repository using commits. Using tags, we c
Recovering a reverted Git commit
Publish Date:2025/04/20 Views:197 Category:OPERATING SYSTEM
-
This article outlines the steps required to revert a reverted Git commit. By the end of this article, you will have the necessary knowledge to recover a reverted commit without rewriting your commit history. Recovering a reverted Git commit
Git merge repository
Publish Date:2025/04/20 Views:160 Category:OPERATING SYSTEM
-
When working on a project with multiple team members having separate repositories for each team, at some point in time we come across a situation where we want to combine these separate repositories into one master repository to deploy all
Git push to another branch with a different name
Publish Date:2025/04/20 Views:57 Category:OPERATING SYSTEM
-
git push It has a rich set of options that allow you to use the full power of Git. One of them is its source:destination refspecs parameters. We use these git push to go to a specific branch with a name of our choosing. Finally, we'll see s
Issues to note when installing Apache on Linux
Publish Date:2025/04/08 Views:78 Category:OPERATING SYSTEM
-
As the most commonly used web server, Apache can be used in most computer operating systems. As a free and open source Unix-like operating system, Linux and Apache are a golden pair. This article will introduce the installation and use of A
在 Git 中标记一个较旧的提交
Publish Date:2023/03/31 Views:187 Category:Git
-
本文概述了在 Git 中标记旧提交所需的步骤。 我们使用 git 标签将我们的提交历史中的特定点标记为重要。