Git log command


The git log command is used to display the commit history of a Git repository. It shows a list of commits with their commit messages, the author of each commit, the date and time the commit was made, and other information. Here are some examples of how to use git log:

Display the commit history:

git log

This will show a list of all commits in the repository, starting with the most recent.

Display the commit history with one line per commit:

git log --oneline

This will show a condensed list of commits, with only the first 7 characters of the commit hash and the commit message.

Display the commit history with the commit message and author:

git log --pretty=format:'%h - %s (%an)'

This will show the commit hash, commit message, and author name for each commit.

Display the commit history for a specific file:

git log --follow <filename>

This will show the commit history for a specific file, including commits where the file was renamed.

Display the commit history for a specific branch:

git log <branch-name>

This will show the commit history for a specific branch. If no branch name is specified, it will show the commit history for the current branch.

Display the commit history for a specific author:

git log --author=<author-name>

This will show the commit history for a specific author. Replace <author-name> with the name of the author you want to filter by.

Display the commit history for a specific date range:

git log --since=<date1> --until=<date2>

This will show the commit history for a specific date range. Replace <date1> and <date2> with the dates you want to filter by. Dates can be in any format recognized by Git, such as YYYY-MM-DD.

Display the commit history with a graph showing the branching and merging:

git log --graph

This will show a graph of the commit history, with lines representing branches and merges.

Display the commit history with the files that were changed in each commit:

git log --stat

This will show a list of files that were changed in each commit, along with the number of lines added and deleted.

Display the commit history with a summary of changes for each commit:

git log --summary

This will show a summary of changes for each commit, including the number of files changed and the number of lines added and deleted.

Display the commit history with a list of commits that introduced a specific string:

git log -S<string>

This will show a list of commits that introduced or removed the specified string. Replace <string> with the string you want to search for.

These are just a few more examples of how to use git log. There are many other options and flags you can use to customize the output to your needs.