Skip to content

Instantly share code, notes, and snippets.

@s-h-a-d-o-w
Created May 3, 2024 18:27
Show Gist options
  • Save s-h-a-d-o-w/841bb5e848872b510cef5770467e2f5a to your computer and use it in GitHub Desktop.
Save s-h-a-d-o-w/841bb5e848872b510cef5770467e2f5a to your computer and use it in GitHub Desktop.
Search the git commit history for a string, with optional duration limit
#!/bin/bash
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <search-string> [last X days]"
exit 1
fi
if [ "$#" -eq 1 ]; then
git --no-pager log --grep="$1"
else
START_DATE=$(date --date="$2 days ago" '+%Y-%m-%d')
git --no-pager log --since="$START_DATE" --grep="$1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment