Git

How to Compare Two Tags With Git?

To point out a specific history of Git tags is useful. Developers can generate multiple tags in the repository. Tags are basically used for capturing particular points in Git commit history for a marked version release, such as “v1.0”, “v2.0”, and many more. Moreover, users can compare the tags based on the changed status of a file or particular file.

The outcomes of this post are:

Comparison Between Two Tags With Git

To compare the two local tags, the “git diff <tag1> <tag2>” command can be used. Try out the previously described command by following the below-given instructions.

Step 1: Switch to Git Root Directory

First, move to the Git root directory by typing out the provided command:

$ cd "C:\Users\nazma\Git"

Step 2: Check Local Tags List

Then, execute the “git tag” command for viewing the list of existing tags:

$ git tag

According to the following output, the current repository contains the “v1.0” and “v2.0” tags:

Step 3: Compare Tags

Next, compare the previously listed local tags by utilizing the “git diff” command along with the tags name:

$ git diff v1.0 v2.0

As you can see, the difference between the above-specified tags are displayed below:

Comparison Between Git Local Tags With Modifications Status

If developers want to compare the local tags with the list of all files that were changed, the following command can be used:

$ git diff v1.0 v2.0 --stat

In the above-stated command, the “–stat” flag indicates the status.

In the below-given output:

  • The list of all files created and modified/changed in the particular tags is displayed.
  • First column contains the file’s name along with the full path.
  • Second column shows the changed status of them.
  • 0” symbol shows a particular file has been changed.
  • 1” symbol represents the deleted files.

Comparison Between Git Local Tags based on Desired File

Another way to compare two different tags based on a particular file, run the provided command:

$ git diff v1.0 v2.0 -- Git/test_dir/file1.py

Here, the “Git/test_dir/file1.py” is a desired file name that is used for comparing the tags for viewing the difference between them:

That’s all! We have compiled the easiest way of comparing two tags with Git.

Conclusion

To compare the two tags in Git, the “git diff” command can be used. Moreover, to compare tags with the changed status of the files, the “git diff <tag1> <tag2> –stat” command is useful. Another way of comparing the tags is by running the “git diff <tag1> <tag2> — <file-name>” command that can be used based on the particular file. This post described the method of comparing two tags in Git.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.