Different Options of annotate Command
annotate command has many options to retrieve different types of information of the files used in the GitHub repository. The purposes of some mostly used options of annotate command have been described below:
Option | Purpose |
-b | It is used to display blank SHA-1 for boundary commits. |
–show-stats | It is used to include additional statistics at the end of the output. |
-L <n,m> | It is used to annotate the line range from n to m. |
-L :<funcname> | It is used to annotate the line based on the function name. |
-l | It is used to display long revision that is off by default. |
-t | It displays the raw timestamp that is off by default. |
-n, –show-number | It is used to display the original line number. |
-e, –show-email | It is used to display the author’s email in place of the name. |
–date <format> | It is used to specify the date format. |
–first-parent | It can be used to determine when a line is mentioned to a particular integration branch rather than to the history. |
–incremental | It is used to display the result incrementally. |
–encoding=<encoding> | It is used to specify the encoding used for the author names and commit summaries. |
-M[<num>] | It is used to detect moved or copied lines within a file. |
-C[<num>] | It is used to detect the lines moved or copied from other files that were modified in the same commit. |
–ignore-rev <rev> | It is used to ignore revision. |
–ignore-revs-file <file> | It is used to ignore revisions listed in the file. |
-h | It is used to show help messages. |
Different Uses of annotate Command:
The following annotate command will display all information of the basic.py file:
The following output shows that each line of the basic.py file is annotated with the SHA, the GitHub username is fyc21, the last committed date and time of the file, and the code of each line.
The following annotate command will display the information of the basic.py file from line number 1 to 3.
The following output shows the same information of the basic.py file as the first annotate command based on the line number mentioned in the command.
The following annotate command will display the information of the basic.py file from line number 4 to -2. Here, the negative value is given for the ending line number that will count the line backward. The basic.py file contains 4 lines. So, the command will display the information from the line 3 to 4 of the basic.py file.
The following output shows the same information of the basic.py file as the first annotate command based on the line number mentioned in the command.
The username of the GitHub account displays by default when the annotate command is executed for any repository file that is published in the remote server. But if you want to retrieve the email address of the GitHub account, then run the following annotate command. The command will display the author’s email address of the basic.py file.
The following output shows the email address of the GitHub account where the repository is published.
The last committed date and time values of the file are displayed by default when the annotate command is executed for the repository file that is published in the remote server. But if you want to retrieve the timestamp value in place of date and time values, then run the following annotate command. The command will display the last timestamp value of the basic.py file.
The following output shows the timestamp value in place of the last committed date and time values of the file:
In the previous outputs, the SHA value is printed in short form. If you want to retrieve the full SHA value of the repository file, then run the following annotate command. The command will display the detailed SHA value of the basic.py file.
The following output shows the full SHA value of the basic.py file with the other information that is mentioned before:
If you want to retrieve the additional statistical information of any repository file with the default information, then run the following annotate command. The command will display the additional information of the basic.py file.
The following output shows the extra three new statistical information of the basic.py file. These are the number of the blob, the number of the patch, and the number of commits.
If you want to retrieve the information of any repository file incrementally, then run the following command. The command will display the incremental results of the basic.py file.
The following output shows the current SHA value, username, email, timestamp values of the author, username, email, timestamp, time zone values of the committer, commit message, and the previous SHA values of the basic.py file.
Conclusion:
The different information of a repository file can be retrieved using the git annotate command. The purposes and the uses of the different options of this command have been explained in this tutorial by creating a demo git repository. I hope the concept of the annotate command will be clear for the readers after reading this tutorial.