Skip to content

Instantly share code, notes, and snippets.

@qrkourier
Forked from anonymous/gist:2523336
Last active January 3, 2016 22:59
Show Gist options
  • Save qrkourier/8532014 to your computer and use it in GitHub Desktop.
Save qrkourier/8532014 to your computer and use it in GitHub Desktop.
#!/bin/bash -eu
git filter-branch --env-filter '
# name, email, and date for author and committer are all set to the preferred
# values unless the override variable is empty or undefined.
# (see git-rewrite-tree(1))
#GIT_AUTHOR_NAME
#GIT_AUTHOR_EMAIL
#GIT_AUTHOR_DATE
#GIT_COMMITTER_NAME
#GIT_COMMITTER_EMAIL
#GIT_COMMITTER_DATE
declare GIT_PREFERRED_EMAIL="";
declare GIT_PREFERRED_NAME="";
declare GIT_PREFERRED_DATE="";
# alternatively, only operate on the committer, not the author
#for GITPTR in GIT_COMMITTER_{NAME,EMAIL,DATE};do
for GITPTR in GIT_{AUTHOR,COMMITTER}_{NAME,EMAIL,DATE};do
# derive the name of the var contining the preferred value by substituting
# whichever of the two possible substrings appears in this iteration of the
# parent loop
for SUBSTR in "AUTHOR" "COMMITTER";do
[[ "$GITPTR" =~ "$SUBSTR" ]] && {
PREFPTR=${GITPTR/$SUBSTR/PREFERRED};
} || continue;
done
# next if preferred value is empty
[[ "${!PREFPTR-}" ]] || continue ;
# reassign value of GITPTR var if it does not exactly match preferred
[[ ${!GITPTR} == ${!PREFPTR} ]] || \
{
export eval ${GITPTR}=${!PREFPTR};
}
done
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment