Skip to content

Instantly share code, notes, and snippets.

@jonathanconway
Created December 14, 2024 02:10
Lists all the unique authors who have edited a given file in the current Git repository
#!/bin/bash
# Generated by ChatGPT.
# Prompt:
# Please write a bash script which finds and lists all the unique authors who
# have edited the given file in the current Git repository. The given file
# will be specified as the first parameter to the bash script.
# Check if a file parameter is provided
if [ -z "$1" ]; then
echo "Usage: $0 <file-path>"
exit 1
fi
# File path passed as the first argument
file_path="$1"
# Check if the file exists in the Git repository
if ! git ls-files --error-unmatch "$file_path" > /dev/null 2>&1; then
echo "Error: '$file_path' is not tracked in the current Git repository."
exit 2
fi
# Extract unique authors who have edited the file
echo "Authors who have edited '$file_path':"
git log --follow --pretty=format:"%an <%ae>" -- "$file_path" | sort | uniq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment