In Git, you can view the commit history of a repository using the git log command. The git log command shows a chronological list of all the commits made in a repository, starting with the most recent commit.
Here’s an example of how to use the git log command:
# View the commit history of the current branch
git log
This command will show a list of all the commits in the current branch, starting with the most recent commit. By default, the git log command shows each commit’s SHA-1 hash, the author, the commit date, and the commit message.
You can also use options with the git log command to customize the output. For example, you can use the –pretty option to format the output of the git log command:
# View the commit history of the current branch with a custom format
git log --pretty=format:"%h - %an, %ar : %s"
This command will show a list of all the commits in the current branch, with a custom format that includes the commit hash, the author’s name, the commit date in a relative format, and the commit message.
In addition to the git log command, there are several other commands you can use to view the commit history of a repository. For example, you can use the git show command to view the details of a specific commit:
# View the details of a specific commit
git show <commit-hash>
This command will show the details of the commit, including the commit message, the changes made in the commit, and the author.
In summary, you can view the commit history of a Git repository using the git log command. This command shows a chronological list of all the commits made in a repository. You can customize the output of the git log command using options such as –pretty. Additionally, you can use the git show command to view the details of a specific commit.