Git is the most common, free and open-source distributed version-controlling system. It has repositories that play a significant part in Git’s world.
There is a huge significance of repositories in the developer’s life as this feature of Git; a developer can look into the past and have ideas regarding the commits that have been made to the project through the feature of Git, which is the
Commits are snapshots of the files we have done by developers during the project’s life cycle. Each snapshot is comprised of whole information in detail about the project.
Every file in the snapshot has its unique identity, “a unique SHA-1 hash”, which is particularly known as “blobs”. A tree specifies these blobs, and the commit specifies that tree.
Commit hashes are the long string that follows the word
commit. It is probably called a Git commit
This section will teach us how to view commits in different scenarios we have made while working on a project with team members.
Methods of Viewing Commit History
View a Specific Commit
We have to look at the specific commit if we have the hash string of that specific commit through Git’s useful command
git show, which will show us the changes for that particular single commit.
Following is an example of that command.
git show 5eba8ab3b718a6ab6610186be934ba214e228a58
Commit hashes can be used shortly rather than specifying the whole big
SHA because all the commit hashes are generally unique so we can use a few starting letters/numbers, and the result would be the same.
View List of Recent Commits
If we want to go through the latest commits and see recent details regarding our project, Git has a very smooth command for this situation, which is very easy to use. We can say that the commit history can be seen in various ways with the help of the command
The above command will result in a chronological list of recent commits in chronological order, showing the recent commit as the first, following the old ones.
commit d240853866f20fc3e536cb3bca86c86c54b487ce Author: test User <Test@user.media> Date: Fri Sept 12 11:44:39 2021 +0100 commit for the first feature
Through this, we will see all the details, including the developer’s name, who made the commit, at what time the developer made it, and the developer’s email id, including the detail of the message they entered at the time of the commit.
View Commit Not Referenced to Any Branch or Tag
The changes done to the branch tips can be tracked through Git’s special feature,
git reflog. It’s particularly related to local and has no concern with the repository.
It helps us view any commit that is not specified to any branch or is not named. We have seen a parameter
ref attached to many Git commands; this parameter indicates references and is used in referencing a commit.
reflog is found in
.git/logs/refs/heads/., which mainly keeps track of the history of local commits for a particular branch, excluding the commits that have been thrown away by
git garbage collection processes. It helps recover deleted branches and commits.
Below is the command we are talking about.
git log --reflog
The above command will come up with all the
git commits by assuming that all the targets stated by reflogs, that is,
git reflog, are mentioned on the specified command line displayed as