In the previous chapters we saw how to add a file to staging area, how to commit a file and many different operations.
In this chapter we shall see the debugging options to know who made the modifications and see some of the logs.
git status
git log
git blame
git tag
git status
“git status” command is used to get the status of working tree between “git add” and “git commit”
We shall see different states a file will go through from “git add” to “git commit” with series of examples:
1. When a new repository is created, “git status” will give below output
2. When you create a new file like “myProg.c”, “git status” will give below output
3. When you add that file to the staging area using “git add .”, “git status” will give below output
4. When you commit the changes using “git commit -m “initial commit” “, below will be git status output:
git log
whenever you commit, 3 things will be recorded:
1. Commit Hash: A 40 character checksum data generated by SHA (Secure Hash Algorithm) algorithm.
2. Commit Author Name
3. Commit Date
When you do “git log”, it will display all the above details from all the commit.
Example:
As I have done only 1 commit, “git log” will give the output as below:
” git log –oneline ” will give commit status in one line
git blame
“git blame” command is used to get the changes made to a file line by line.
It will have the author who made the change and the date of modification.
Example:
git tag
git tag is used to give a name for important releases in the project. Once you give tag to a branch, it will loose ability to change the history of commits.
How to view tags?
Use “git tag” command to list all the tags.
How to create a tags ?
There are 2 types to create a tags:
1. Annotated Tags :
It is used to add extra metadata like author name, release notes, tag-message.
Use “git tag -a” command.
Example:
git tag -a v1.5
or
git tag -a v1.5 -m “this version has XYZ fix”
2. Lightweight Tags
It is a simple tag. It will only store the hash of the commit.
Use “git tag” to create a lightweight tag.
Example:
git tag v1.5.5