Back to roadmaps git Course

Reviewing History: git log and git diff

Once you make commits, you need ways to view history logs and check exactly what changed.


1. Viewing Commit Histories with git log

To list the history of commits in your active branch:

git log

This command shows the author, date, hash, and message for every commit.

Useful Log Flags

# Print each commit on a single line
git log --oneline

# Display the commit tree topology graph along with tags
git log --oneline --graph --all

2. Comparing Code Changes with git diff

Use git diff to see modifications that have not been staged yet:

# Compare working directory against the staging area
git diff

Comparing Staged Changes

To see changes that are in the Staging Area, compare them against your last commit:

# Compare staged files against HEAD commit
git diff --staged

Comparing Commits

To compare changes between two specific commits, use their hashes:

# Compare Commit A against Commit B
git diff commit_hash_A commit_hash_B
Published on Last updated: