my-notes

git_detailed_history

1 min read

git detailed history

Advanced history navigation and analysis.


πŸ“œ Log Formats

One Line

git log --oneline

Compact: hash + message.


Graph View

git log --graph --oneline --all

Visual branch structure.


With Diff

git log -p

Shows patch for each commit.


With Stats

git log --stat

Shows files changed per commit.


πŸ” Filter by Author

By Name

git log --author="John"

Commits by author containing "John".


By Email

git log --author="john@email.com"

Commits by specific email.


πŸ“… Filter by Date

Since Date

git log --since="2024-01-01"

Commits after date.


Until Date

git log --until="2024-06-01"

Commits before date.


Relative Date

git log --since="2 weeks ago"

Commits from last 2 weeks.


πŸ’¬ Filter by Message

By Message Content

git log --grep="bug fix"

Commits with "bug fix" in message.


Case Insensitive

git log --grep="bug" -i

Case insensitive search.


πŸ“ Filter by File

By Path

git log -- path/to/file.txt

Commits touching this file.


Follow Renames

git log --follow -- path/to/file.txt

Tracks file through renames.


πŸ“ Filter by Code

By Code Change (Pickaxe)

git log -S "function_name"

Commits that added/removed this string.


By Regex

git log -G "pattern.*match"

Commits matching regex pattern.


πŸ‘€ git blame

See Line Authors

git blame file.txt

Shows who last modified each line.


Specific Lines

git blame -L 10,20 file.txt

Blame only lines 10-20.


Ignore Whitespace

git blame -w file.txt

Ignores whitespace changes.


πŸ“Š Statistics

Commits by Author

git shortlog -sn

Commit count by author.


With Emails

git shortlog -sne

Includes email addresses.


πŸ“ˆ Custom Format

Format Placeholders

Placeholder Meaning
%H Full hash
%h Short hash
%an Author name
%s Subject
%ar Relative date

Custom Format Example

git log --pretty=format:"%h %an %s"

Short hash, author, subject.


Colored Output

git log --pretty=format:"%C(yellow)%h%Creset %s"

Yellow hash, normal subject.


πŸ’‘ Tips

Create Log Alias
git config --global alias.lg "log --oneline --graph --all"
Find Deleted Code
git log -S "deleted_code" --all


#git #log #history #blame #internals

Built with mdgarden