Skip to main content

Synopsis

git log [<options>] [<revision-range>] [[--] <path>...]

Description

Shows the commit logs. The command takes options to control what is shown and how, including options to control how the changes each commit introduces are shown. List commits that are reachable by following the parent links from the given commit(s). By default, it shows all commits reachable from HEAD.

Common Usage

1

View commit history

Display the commit log:
git log
2

Show with diffs

View commits with their changes:
git log -p
3

Limit output

Show only the last N commits:
git log -3
4

View history for file

Show commits that affected a specific file:
git log --follow file.txt

Options

-<number>, -n <number>, --max-count=<number>Limit the number of commits to output.--skip=<number>Skip the specified number of commits before starting to show the commit output.--since=<date>, --after=<date>Show commits more recent than a specific date.--until=<date>, --before=<date>Show commits older than a specific date.--author=<pattern>Limit the commits output to ones with author matching the specified pattern.--committer=<pattern>Limit the commits output to ones with committer matching the specified pattern.--grep=<pattern>Limit the commits output to ones with log message that matches the specified pattern.
--onelineShow each commit on a single line. Shorthand for --pretty=oneline --abbrev-commit.--decorate[=(short|full|auto|no)]Print out the ref names of any commits that are shown. Default to configuration value of log.decorate if configured, otherwise auto.--graphDraw a text-based graphical representation of the commit history on the left side of the output.--statGenerate a diffstat showing which files were changed and by how much.--shortstatOutput only the last line of the --stat format containing total number of modified files, as well as number of added and deleted lines.--name-onlyShow only names of changed files.--name-statusShow only names and status of changed files.--abbrev-commitShow only a partial prefix of the commit object name instead of the full 40-byte hexadecimal object name.
--pretty[=<format>], --format=<format>Pretty-print the contents of the commit logs in a given format. Options include:
  • oneline - Commit hash and message on one line
  • short - Hash, author, and message
  • medium - Default format
  • full - Hash, author, committer, and message
  • fuller - Like full but with dates
  • format:<string> - Custom format string
--date=<format>Show dates in the specified format. Options include relative, iso, rfc, short, raw, human, and unix.--no-mergesDo not print commits with more than one parent (merge commits).--first-parentFollow only the first parent commit upon seeing a merge commit.
-p, --patchGenerate patch (show diff for each commit).-uSynonym for -p.--patch-with-statEquivalent to -p --stat.--unified=<n>Generate diffs with <n> lines of context instead of the usual three.--full-diffShow the full diff for commits that touch the specified paths, not just the changes to those paths.
--followContinue listing the history of a file beyond renames (works only for a single file).--allShow commits from all branches and tags.--branches[=<pattern>]Show commits from all branches matching the pattern.--tags[=<pattern>]Show commits from all tags matching the pattern.--remotes[=<pattern>]Show commits from all remote-tracking branches matching the pattern.-L <start>,<end>:<file>Trace the evolution of a line range within a file.
--mailmap, --no-mailmap, --use-mailmap, --no-use-mailmapUse mailmap file to map author and committer names and email addresses to canonical real names and email addresses.--sourcePrint out the ref name given on the command line by which each commit was reached.--log-sizeInclude a line “log size <number>” in the output for each commit, where number is the length of that commit’s message in bytes.

Revision Range

<revision-range> Show only commits in the specified revision range. When no revision range is specified, it defaults to HEAD (i.e. the whole history leading to the current commit). Common formats:
  • <commit> - Show history from the specified commit
  • <commit1>..<commit2> - Show commits reachable from commit2 but not commit1
  • <commit1>...<commit2> - Show commits reachable from either commit but not both
  • origin..HEAD - Show commits in current branch not yet pushed

Examples

View recent history

$ git log
Shows the commit history with full details.

One-line format with graph

$ git log --oneline --graph --all
* a1b2c3d (HEAD -> main) Update documentation
* e4f5g6h Fix bug in parser
* i7j8k9l Add new feature

Show commits from last 2 weeks

$ git log --since="2 weeks ago"

View commits for specific file

$ git log --follow -- file.txt
Shows the history of file.txt, including renames.

Show commits with diffs

$ git log -p -2
Shows the last 2 commits with their full diffs.

View commits in date range

$ git log --since="2024-01-01" --until="2024-12-31"

Show commits by author

$ git log --author="John Doe"

Search commit messages

$ git log --grep="fix"
Shows commits with “fix” in the commit message.

Show no merge commits

$ git log --no-merges
Skip merge commits, showing only direct changes.

Compare branches

$ git log main..feature
Shows commits in feature branch that are not in main.

Show commits affecting specific paths

$ git log v2.6.12.. include/scsi drivers/scsi
Shows all commits since version v2.6.12 that changed files in the specified directories.

Pretty format with statistics

$ git log --stat --oneline --graph -5
Shows the last 5 commits with file change statistics in a compact graphical format.

Trace line history

$ git log -L '/int main/',/^}/:main.c
Shows how the function main() in main.c evolved over time.

Show unpushed commits

$ git log origin/main..HEAD
Shows commits in your local branch that haven’t been pushed to origin yet.

Custom format

$ git log --pretty=format:"%h - %an, %ar : %s"
a1b2c3d - John Doe, 2 days ago : Fix bug
e4f5g6h - Jane Smith, 1 week ago : Add feature
Uses a custom format string to display commit information.
  • git status - Show the working tree status
  • git commit - Record changes to the repository
  • git diff - Show changes between commits
  • git show - Show various types of objects
  • git reflog - Show reference logs
  • git rev-list - List commit objects in reverse chronological order

Build docs developers (and LLMs) love