The git log
command allows you to view all the previous commits in your repository, with the most recent commits appearing first. By default, it shows all the commits of the currently checked out branch.
Initial Example
$ git log
LOG Options
Option | Description |
---|---|
--all | Show commits from all branches. |
--pretty | Customize the log output format. Possible values: oneline , short , full , fuller , etc. |
--graph | Show a graphical representation of the commit history. |
--author | Show commits by a specific author. Example: --author="Author Name" . |
-n <number> | Limit the number of commits shown. Example: -n 5 to show the last 5 commits. |
--since | Show commits more recent than a specific date. Example: --since="2023-01-01" . |
--until | Show commits older than a specific date. Example: --until="2023-01-01" . |
--oneline | Show each commit as a single line. |
--decorate | Show ref names along with the commit message. |
--stat | Show statistics for files modified in each commit. |
--patch | Show the full diff of each commit. |
--name-only | Show only the names of the files that were changed. |
--name-status | Show the names and status of files that were changed. |
--abbrev-commit | Show only the first few characters of the SHA-1 hash. |
--relative-date | Show dates relative to the current time (e.g., “2 weeks ago”). |
--reverse | Show commits in reverse order. |
--grep | Show only commits with a commit message matching the given pattern. Example: --grep="fix" . |
--first-parent | Show only the first parent commits of merge commits. |
Examples
1. Show All Commits
Shows all the commits of the currently checked out branch.
$ git log
2. Show All Commits from All Branches
Forces Git to show all commits from all branches.
$ git log --all
3. Show Commits with Detailed Information
Displays each commit with detailed information like author, date, and message.
$ git log --pretty=fuller
4. Show Commits with Graph
Shows a graphical representation of the commits.
$ git log --graph
5. Show Commits of a Specific Author
Shows only the commits made by a specific author.
$ git log --author="Author Name"
6. Limit the Number of Commits
Limits the log output to a specified number of commits.
$ git log -n 5
Replace 5
with the desired number of commits.