Git Log and History

Section 4: Git Log and History

Viewing Commit History with git log

Basic Log Command

To view the commit history:

git log


Limiting Log Output

Limit the number of commits displayed:

git log -n 5  # Shows the last 5 commits

Formatting Log Output

Customize log output with formatting options:

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


Git Tags

Creating Lightweight Tags

Create a lightweight tag:

git tag v1.0

Creating Annotated Tags

Create an annotated tag:

git tag -a v1.1 -m "Version 1.1"

Viewing Tags

List all tags:

git tag

Navigating to a Tag

Switch to a specific tag:

git checkout v1.0

Referencing Tags

Reference tags in commits (replace TAG_NAME):

git show TAG_NAME

This section covers using git log to view the commit history, including filtering and formatting options. It also introduces Git tags, both lightweight and annotated, for marking specific points in the history and navigating to them. Understanding these commands is crucial for tracking changes and managing versions in a Git repository.