Files
dotfiles/bin/git-fix-author
Eric Wagoner a20358865a Add custom git commands to dotfiles repo
Include git-branch-backup, git-fix-author, git-name-stash,
git-name-stash-apply, git-rebase-on, and git-rename-branch in a new
bin/ directory. Update install.sh to symlink them into ~/bin and
document them in the README.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 10:43:09 -04:00

51 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
OLD=""
NEW_NAME=""
NEW_EMAIL=""
ARGS=$(getopt -o o:n:h -l "old:,new:,help" -n $0 -- "$@")
[ $? -eq 0 ] || exit 1
eval set -- "$ARGS"
while true
do
case "$1" in
-o|--old)
OLD=$2
shift 2
;;
-n|--new)
NEW=$2
NEW_NAME=$(echo "$NEW" | awk -F'[<>]' '{print $1}' | sed 's/ *$//')
NEW_EMAIL=$(echo "$NEW" | awk -F'[<>]' '{print $2}')
shift 2
;;
-h|--help)
echo "usage: git fix-author --old diz@cpan.org --new 'Mike Eldridge <mike.eldridge@iinteractive.com>' ref"
exit
;;
--)
shift
break
;;
esac
done
echo "OLD=\"$OLD\""
echo "NEW_NAME=\"$NEW_NAME\""
echo "NEW_EMAIL=\"$NEW_EMAIL\""
git filter-branch --commit-filter "
if [ \"\$GIT_COMMITTER_EMAIL\" = \"$OLD\" ];
then
GIT_COMMITTER_NAME=\"$NEW_NAME\";
GIT_AUTHOR_NAME=\"$NEW_NAME\";
GIT_COMMITTER_EMAIL=\"$NEW_EMAIL\";
GIT_AUTHOR_EMAIL=\"$NEW_EMAIL\";
git commit-tree \"\$@\";
else
git commit-tree \"\$@\";
fi" $@