DEV Community

Cover image for Day 22/30 - git log --graph --oneline --all – Visualize branch history.
Ruqaiya Beguwala
Ruqaiya Beguwala

Posted on • Originally published at Medium

Day 22/30 - git log --graph --oneline --all – Visualize branch history.

Introduction: Why Visualizing Git History Matters

In collaborative software development, keeping track of branches, merges, and commit histories is essential. Without a clear view of how changes propagate across branches, developers can easily lose track of work, leading to merge conflicts, lost commits, and confusion.

Git provides powerful tools to inspect repository history, but the default git log output can be overwhelming. That’s where git log --graph --oneline --all comes in—it condenses commit history into an easy-to-read graph, showing branch relationships at a glance.

Let’s dive in!


How to Use git log --graph --oneline --all

Breaking Down the Command

The command combines three key flags:

Flag Purpose
--graph Displays commit history as a branching graph
--oneline Shows each commit in a single line (hash + message)
--all Includes all branches (not just the current one)

Basic Syntax

git log --graph --oneline --all
Enter fullscreen mode Exit fullscreen mode

Example Output Explained

Here’s a sample output from a repository with multiple branches:

*   8a2b3c4 (HEAD -> main) Merge feature/auth  
|\  
| * d5e6f7g (feature/auth) Implement OAuth login  
| * e8f9h0i Add user authentication middleware  
|/  
* b3c4d5e Refactor database schema  
* c6d7e8f Initial project setup  
Enter fullscreen mode Exit fullscreen mode

What This Tells Us:

  • The latest commit (8a2b3c4) is a merge of feature/auth into main.
  • The feature/auth branch had two commits (d5e6f7g and e8f9h0i).
  • Before the branch existed, there were two commits (b3c4d5e and c6d7e8f) on main.

Common Use Cases for Branch Visualization

1. Tracking Merges and Divergences

When working in a team, multiple branches may be active at once. This command helps identify:

  • Which branches have been merged
  • Which branches are still pending

Example:

git log --graph --oneline --all --since="2 weeks ago"
Enter fullscreen mode Exit fullscreen mode

This shows only recent activity, making it easier to catch up on changes.

2. Debugging Complex Branching Scenarios

If a merge conflict arises, visualizing history helps pinpoint where branches diverged.

Example:

git log --graph --oneline --all -- path/to/file
Enter fullscreen mode Exit fullscreen mode

This filters commits that modified a specific file, showing how changes propagated.

3. Auditing Changes by Author

To see contributions from a specific developer:

git log --graph --oneline --all --author="Alice"
Enter fullscreen mode Exit fullscreen mode

4. Finding Orphaned Commits (Unmerged Branches)

Sometimes, branches are abandoned without merging. Detect them with:

git log --graph --oneline --all --no-merges
Enter fullscreen mode Exit fullscreen mode

Tips and Tricks for Advanced Git Log Usage

Git's log command is far more powerful than most developers realize. Beyond basic history viewing, it offers sophisticated filtering, formatting, and visualization options that can supercharge your workflow. Here's an in-depth guide to getting the most from git log.

1. Powerful Visualization Techniques

Enhanced Branch Graphing

git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
Enter fullscreen mode Exit fullscreen mode

This command gives you:

  • Color-coded output for better readability
  • Relative dates ("2 hours ago" instead of timestamps)
  • Author information
  • Branch/tag decorations

ASCII Art with --graph

For complex branch histories, add --graph to see relationships:

git log --all --graph --oneline --decorate
Enter fullscreen mode Exit fullscreen mode

2. Sophisticated Filtering Options

Time-Based Filtering

# Last week's commits
git log --since="1 week ago"

# Commits between two dates
git log --since="2024-01-01" --until="2024-02-01"

# Commits from last 2 days
git log --since="2.days.ago"
Enter fullscreen mode Exit fullscreen mode

Author and Committer Search

# By exact name
git log --author="John Doe"

# By email domain
git log --author="@company.com"

# Committer vs Author (useful for rebases)
git log --committer="Jane Smith"
Enter fullscreen mode Exit fullscreen mode

Content-Based Filtering

# Commits touching specific files
git log -- path/to/file

# Commits containing string in message
git log --grep="bugfix"

# Commits adding/removing specific code
git log -S"function_name"  # Search by string
git log -G"regex_pattern"  # Search by regex
Enter fullscreen mode Exit fullscreen mode

3. Advanced Formatting Tricks

Custom Output Formats

git log --pretty=format:'%h | %ad | %s (%an)' --date=short
Enter fullscreen mode Exit fullscreen mode

Common format placeholders:

  • %h: Abbreviated commit hash
  • %ad: Author date
  • %s: Subject
  • %an: Author name
  • %d: Ref names
  • %cr: Relative committer date

JSON Output for Scripting

git log --pretty=format:'{%n  "commit": "%H",%n  "author": "%an",%n  "date": "%ad",%n  "message": "%f"%n},' --date=iso
Enter fullscreen mode Exit fullscreen mode

4. Statistical Insights

Commit Frequency

git log --pretty=format:%ad --date=short | uniq -c
Enter fullscreen mode Exit fullscreen mode

Shows commits per day.

Author Contribution Stats

git shortlog -sn --all --no-merges
Enter fullscreen mode Exit fullscreen mode

5. Bonus Aliases for Your .gitconfig**

[alias]
    # Compact tree view
    tree = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative

    # Show recent activity
    recent = log --all --graph --oneline --decorate -n 20

    # Find commits by message
    find = "!f() { git log --all --grep=\"$1\"; }; f"

    # Stats per author
    stats = shortlog -sn --all --no-merges

    # Who changed what in a file
    blame-who = "!f() { git blame -w -M -C \"$1\" | awk '{print $2}' | sort | uniq -c | sort -nr; }; f"
Enter fullscreen mode Exit fullscreen mode

Conclusion: Mastering Git Branch Visualization

git log --graph --oneline --all is one of the most powerful commands for understanding Git history. Whether you’re:

  • Debugging merge conflicts
  • Reviewing team contributions
  • Cleaning up old branches
  • Auditing changes

…this command provides clarity in seconds.


Up Next in the Series: git shortlog – Summarize commit contributions by author


Daily advance GIT tips in your inbox---worth starting? Respond to my poll here🚀

For more useful and innovative tips and tricks, Let's connect on Medium

Top comments (2)

Collapse
 
ranjan_devto profile image
Ranjan Majumdar

This is so useful. Thank you @ruqaiya_beguwala

Collapse
 
ruqaiya_beguwala profile image
Ruqaiya Beguwala

Glad that you like it. You can check other parts of this series as well. Hope you find something useful.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.