unixorn/git-extra-commands

View on GitHub
bin/git-related

Summary

Maintainability
Test Coverage
#!/usr/bin/env bash
# Usage: git related <file>
#
# Show other files that often get changed in commits that touch `<file>`.
# Author: Mislav Marohnić

set -e

file="${1?}"

git blame -w --porcelain -- "$file" | awk '
  /^[0-9a-f]{40} / { sha = $1 }
  /^author-time / { print(sha) }
' | sort -u | grep -v '^0\+$' | xargs -I % git diff -w --name-only "%^..%" \
  | grep -v "$file" | sort | uniq -c | sort -rn