mirror of
https://github.com/mintlify/docs.git
synced 2026-09-14 13:35:46 +08:00
261 lines
3.6 KiB
Plaintext
261 lines
3.6 KiB
Plaintext
---
|
|
title: git log
|
|
description: Show commit logs
|
|
---
|
|
|
|
View the commit history of your repository.
|
|
|
|
## Syntax
|
|
|
|
```bash
|
|
git log [options] [<revision-range>]
|
|
```
|
|
|
|
## Description
|
|
|
|
`git log` displays commits in reverse chronological order (newest first). Each entry shows the commit hash, author, date, and message.
|
|
|
|
## Common usage
|
|
|
|
View commit history:
|
|
|
|
```bash
|
|
git log
|
|
```
|
|
|
|
Compact one-line format:
|
|
|
|
```bash
|
|
git log --oneline
|
|
```
|
|
|
|
## Options
|
|
|
|
<ParamField path="--oneline" type="flag">
|
|
Show each commit on a single line
|
|
|
|
```bash
|
|
git log --oneline
|
|
```
|
|
</ParamField>
|
|
|
|
<ParamField path="--graph" type="flag">
|
|
Draw a text-based graph of branches
|
|
|
|
```bash
|
|
git log --graph --oneline
|
|
```
|
|
</ParamField>
|
|
|
|
<ParamField path="-n" type="number">
|
|
Limit number of commits shown
|
|
|
|
```bash
|
|
git log -n 5
|
|
```
|
|
</ParamField>
|
|
|
|
<ParamField path="--since" type="string">
|
|
Show commits after a specific date
|
|
|
|
```bash
|
|
git log --since="2 weeks ago"
|
|
```
|
|
</ParamField>
|
|
|
|
<ParamField path="--author" type="string">
|
|
Filter by author
|
|
|
|
```bash
|
|
git log --author="John"
|
|
```
|
|
</ParamField>
|
|
|
|
<ParamField path="--grep" type="string">
|
|
Search commit messages
|
|
|
|
```bash
|
|
git log --grep="fix"
|
|
```
|
|
</ParamField>
|
|
|
|
## Examples
|
|
|
|
### Basic log
|
|
|
|
```bash
|
|
git log
|
|
```
|
|
|
|
### One-line format
|
|
|
|
```bash
|
|
git log --oneline
|
|
```
|
|
|
|
Output:
|
|
```
|
|
abc1234 Add user authentication
|
|
def5678 Fix navigation bug
|
|
ghi9012 Update documentation
|
|
```
|
|
|
|
### Pretty graph
|
|
|
|
```bash
|
|
git log --graph --oneline --all --decorate
|
|
```
|
|
|
|
### Last 5 commits
|
|
|
|
```bash
|
|
git log -5
|
|
```
|
|
|
|
### Commits by author
|
|
|
|
```bash
|
|
git log --author="Jane Doe"
|
|
```
|
|
|
|
### Commits in date range
|
|
|
|
```bash
|
|
git log --since="2024-01-01" --until="2024-01-31"
|
|
```
|
|
|
|
### Search commit messages
|
|
|
|
```bash
|
|
git log --grep="authentication"
|
|
```
|
|
|
|
### Commits affecting specific file
|
|
|
|
```bash
|
|
git log -- path/to/file.txt
|
|
```
|
|
|
|
## Custom formatting
|
|
|
|
### Short format
|
|
|
|
```bash
|
|
git log --pretty=format:"%h - %an, %ar : %s"
|
|
```
|
|
|
|
Output:
|
|
```
|
|
abc1234 - John, 2 days ago : Add user authentication
|
|
def5678 - Jane, 1 week ago : Fix navigation bug
|
|
```
|
|
|
|
### Format placeholders
|
|
|
|
- `%H` - Commit hash
|
|
- `%h` - Abbreviated hash
|
|
- `%an` - Author name
|
|
- `%ae` - Author email
|
|
- `%ar` - Author date, relative
|
|
- `%s` - Subject (commit message)
|
|
- `%b` - Body
|
|
|
|
## Common workflows
|
|
|
|
### Review recent work
|
|
|
|
```bash
|
|
git log --oneline -10
|
|
```
|
|
|
|
### See what changed in a commit
|
|
|
|
```bash
|
|
git log -p -1
|
|
```
|
|
|
|
### View branch history
|
|
|
|
```bash
|
|
git log --graph --oneline --all
|
|
```
|
|
|
|
### Find specific change
|
|
|
|
```bash
|
|
git log -S "function_name"
|
|
```
|
|
|
|
This searches for commits that added or removed "function_name".
|
|
|
|
### Commits not yet pushed
|
|
|
|
```bash
|
|
git log origin/main..HEAD
|
|
```
|
|
|
|
## Navigating log output
|
|
|
|
When viewing logs:
|
|
|
|
- Press `Space` to scroll down
|
|
- Press `b` to scroll up
|
|
- Press `q` to quit
|
|
- Press `/` to search
|
|
- Press `n` for next search result
|
|
|
|
## Filtering examples
|
|
|
|
### Commits from last week
|
|
|
|
```bash
|
|
git log --since="1 week ago"
|
|
```
|
|
|
|
### Commits by date range
|
|
|
|
```bash
|
|
git log --since="2024-01-01" --until="2024-12-31"
|
|
```
|
|
|
|
### Merge commits only
|
|
|
|
```bash
|
|
git log --merges
|
|
```
|
|
|
|
### No merge commits
|
|
|
|
```bash
|
|
git log --no-merges
|
|
```
|
|
|
|
### Changes to specific directory
|
|
|
|
```bash
|
|
git log -- src/components/
|
|
```
|
|
|
|
## Useful aliases
|
|
|
|
Add these to your `.gitconfig`:
|
|
|
|
```bash
|
|
git config --global alias.lg "log --graph --oneline --all --decorate"
|
|
git config --global alias.hist "log --pretty=format:'%h %ad | %s%d [%an]' --date=short"
|
|
```
|
|
|
|
Then use:
|
|
|
|
```bash
|
|
git lg
|
|
git hist
|
|
```
|
|
|
|
## Related commands
|
|
|
|
- [git show](/git/show) - Show commit details
|
|
- [git diff](/git/diff) - Compare changes
|
|
- [git reflog](/git/reflog) - Reference logs
|
|
- [git blame](/git/blame) - Line-by-line authorship
|