~/git/practical-guide-how-git-log-command.md

A Practical Guide on how to work with Git log command and history

2 min readJuly 07, 2020by Gorav Singal#git
// TL;DR

Use git log with options like --oneline, --graph, and --decorate to visualize commit history, and apply filters to narrow down log output effectively.

A Practical Guide on how to work with Git log command and history

Introduction

In this post, we will see ways to look at git history logs.

For other git training posts, visit:

git log

There are log of options with this command. Try this

git help log

Run simple git log command. Example Output:

commit e7dd2a062d569a9fc577180acde0a2b7a0a570f6 (HEAD -> master, origin/master, origin/HEAD)
Author: Gorav Singal <[email protected]>
Date:   Wed Jul 8 11:49:10 2020 +0530
    t2
commit 007675fed3657a0b194386c8c0efbeac2e1fbbed
Author: Gorav Singal <[email protected]>
Date:   Wed Jul 8 11:49:01 2020 +0530
    t1
commit 1a2af9c018e83aa0adef0684875ab7c33499b7d0
Author: Gorav Singal <[email protected]>
Date:   Wed Jul 8 11:45:46 2020 +0530

    test

I’ve ommitted few lines in above output. This output shows commits in reverse order. The most recent commit is on top. It shows a commit id, author, and date.

Shorter commit ids

There is another command to get this history, with shorter commit ids.

git log --abbrev-commit

This shows shorter length of commit it. Typically this is only required to uniquely identify your commit.

Another short version with some graph

Lets see another shorter version of output:

git log --oneline --graph --decorate

# oneline - is for compact output
# graph - some sort of graphical representation of commit history
# decorate - shows any tags, labels etc

# Output

* e7dd2a0 (HEAD -> master, origin/master, origin/HEAD) t2
* 007675f t1
* 1a2af9c test
* f997108 test
* 9a5a776 test
* 85587c6 test1
* 574c251 test 1

Get range of commit ids

git log 1a2af9c...85587c6

You will get commit history with in this commit id range only.

Get history for last 5 days only

git log --since="5 days ago"

Get history for specific file

git log -- <file>

Get detailed info about a single commit

$ git show 574c251142008b98c74d2bed708d05953acd3f0e

commit 574c251142008b98c74d2bed708d05953acd3f0e
Author: Gorav Singal <[email protected]>
Date:   Tue Jul 7 14:14:56 2020 +0530

    test 1

diff --git a/test1.txt b/test1.txt
new file mode 100644
index 0000000..45b983b
--- /dev/null
+++ b/test1.txt
@@ -0,0 +1 @@
+hi

It has commit-id, author info, date, and the actual diff too.

$ subscribe --weekly

One deep dive a week, in your inbox

System design, AI engineering, trading systems and interview prep. Tested code, real numbers. Free, and you can unsubscribe any time.

or read it on gyanbyte.substack.com

Share

Related Posts

A Practical Guide in understanding Git Branch and Conflict resolution during merge

A Practical Guide in understanding Git Branch and Conflict resolution during merge

Introduction In this guide, We will learn about branching, handling conflict…

A Practical Guide on Understanding Git Best Practices

A Practical Guide on Understanding Git Best Practices

Introduction In this post, we will learn about some of Best practices while…

A Practical Guide on how to work with Git Basic Commands and workflows

A Practical Guide on how to work with Git Basic Commands and workflows

Introduction In this guide, we will see git basic commands, and fundamentals of…

A Practical Guide on how to to create your own git command alias

A Practical Guide on how to to create your own git command alias

Introduction In this guide, We will learn on how to create some handy command…

A Practical Guide for better understanding Git Diff

A Practical Guide for better understanding Git Diff

Introduction In this guide, We will get basic understanding of various options…

Git - How to create a Pull Request with no history of commits

Git - How to create a Pull Request with no history of commits

Introduction If you working on a github project in a team. Consider you have…

Latest Posts

How to Stay Valuable as a Software Engineer in the AI Era: A Practical Playbook

How to Stay Valuable as a Software Engineer in the AI Era: A Practical Playbook

In the previous article I argued that AI is not killing software engineering…

How to Review AI-Generated Code: A Checklist for Catching What the Model Missed

How to Review AI-Generated Code: A Checklist for Catching What the Model Missed

A few months back I approved a PR that was almost entirely AI-generated. It…

How to Debug AI-Generated Code: Understand First, Fix Last

How to Debug AI-Generated Code: Understand First, Fix Last

In the last article I wrote about reviewing AI code before it goes in. This one…

The Future of Software Engineering: What AI Changes, What Stays, and Where the Jobs Go

The Future of Software Engineering: What AI Changes, What Stays, and Where the Jobs Go

Every few weeks somebody sends me a scary headline — “AI will replace all…

The Transactional Outbox Pattern: Never Lose an Event Again

The Transactional Outbox Pattern: Never Lose an Event Again

This is one of those patterns that looks like nothing until you get burnt once…

Event Sourcing, Explained: Store What Happened, Not Just the Final State

Event Sourcing, Explained: Store What Happened, Not Just the Final State

Here is a question I like to ask in interviews: your bank account shows a…