Synopsis
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
Options
Commit Limiting
Commit Limiting
-<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.Display Options
Display Options
--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.Formatting Options
Formatting Options
--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 lineshort- Hash, author, and messagemedium- Default formatfull- Hash, author, committer, and messagefuller- Like full but with datesformat:<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.Diff Options
Diff Options
-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.History Options
History Options
--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 and Miscellaneous
Mailmap and Miscellaneous
--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 bothorigin..HEAD- Show commits in current branch not yet pushed
Examples
View recent history
One-line format with graph
Show commits from last 2 weeks
View commits for specific file
file.txt, including renames.
Show commits with diffs
View commits in date range
Show commits by author
Search commit messages
Show no merge commits
Compare branches
feature branch that are not in main.
Show commits affecting specific paths
Pretty format with statistics
Trace line history
main() in main.c evolved over time.
Show unpushed commits
Custom format
Related Commands
- 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
