The git log command shows committed snapshots. It is used for listing and filtering the project history, and searching for particular changes. The git log only works on the committed history in comparison with git status controlling the working directory and the staging area.
The git log command is a tool used for examining a repository’s history and finding a particular version of a project. Log output can be personalized differently, from filtering commits to displaying them in an entirely user-defined format. Here is the list of most commonly used configurations of git log:
|git log||By default formatting, shows the whole commit history. Uses space for scrolling, and q for exiting if the log output takes up multiple screens.|
|git log -n <limit>||Limits the number of commits. For example, git log -n 2 displays only 2 commits.|
|git log --oneline||Fits each commit on a single line which is useful for an overview of the project history.|
|git log --stat||Includes changed files and the number of added or deleted lines from them besides the git log information.|
|git log -p||Shows the patch for each commit as well as their full diff.|
|git log --author="<pattern>"||Searches for commits by a specified author. The <pattern> argument can be a string or a regex.|
|git log --grep="<pattern>"||Searches for commits with a commit message. The <pattern> argument can be a string or a regex.|
|git log <since>..<until>||Displays only commits that occur between <since> and <until> arguments. Both can be either a commit ID, a branch name, HEAD, or any other kind of revision reference.|
|git log <file>||Displays those commits that include the specified file. which makes it easier to see file’s history.|
|git log --graph --decorate --oneline||The --graph flag draws a text based graph of the commits on the left hand side of the commit messages. The --decorate flag adds the names of branches or tags of the displayed commits. The --online flag displays the commit information on a single line making it easier to immediately browse through commits.|
All the above mentioned options can be combined into the following command:
git log --author="Bob Smith" -p w3docs.txt
The given example will show a full diff of all the changes that the author has made to the file w3docs.txt.
The .. syntax is used for comparing branches:
git log --oneline master..some-feature
This example shows a brief overview of all the commits that are in some-feature instead of master.