The outcomes of this post are:
- Comparison Between Two Tags With Git
- Comparison Between Git Local Tags With Modifications Status
- Comparison Between Git Local Tags based on Desired File
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:
Step 2: Check Local Tags List
Then, execute the “git tag” command for viewing the list of existing tags:
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:
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:
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:
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.