Skip to content

Instantly share code, notes, and snippets.

@singularitti
Created March 3, 2026 02:36
Show Gist options
  • Select an option

  • Save singularitti/28c866373d4d8545eaab5366143ecd92 to your computer and use it in GitHub Desktop.

Select an option

Save singularitti/28c866373d4d8545eaab5366143ecd92 to your computer and use it in GitHub Desktop.
Generate Git commit log within a range #Git #Shell #versioning #devops
git_log_range() {
"""
Print full multiline Git commit messages between two revisions.
Args:
$1 (string): Start revision (exclusive). Example: v1.2.0
$2 (string): End revision (inclusive). Example: HEAD
Defaults to HEAD if not provided.
Behavior:
- Outputs commits reachable from <end> but not from <start>
- Preserves full multiline commit messages (subject + body)
- Prints commits in chronological order (oldest → newest)
- Separates commits with a clear delimiter line "----"
Example:
git_log_range v1.2.0 HEAD
git_log_range v1.2.0
"""
local start="$1"
local end="${2:-HEAD}"
if [ -z "$start" ]; then
echo "Error: start revision required (e.g., v1.2.0)"
return 1
fi
git log "${start}..${end}" \
--reverse \
--pretty=format:"----%n%B"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment