Skip to content

Instantly share code, notes, and snippets.

@robison
Created July 11, 2017 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robison/8c4f25acadbce15c7106f32816f2a906 to your computer and use it in GitHub Desktop.
Save robison/8c4f25acadbce15c7106f32816f2a906 to your computer and use it in GitHub Desktop.
#!/bin/sh
OLDIFS=$IFS
IFS=$'\n\t'
for commit in $( git fsck --unreachable HEAD | awk '$2 == "commit" {print substr($3,1,7)}' )
do
printf "\nGit orphan: ${commit}\n"
printf "%s\n" $( TZ=UTC git log -1 --date=iso-local --pretty=format:"parents: %<(24)%porphan: %<(10)%h%<(30)%an%<(26)%ad%s" ${commit} )
parents=()
IFS=$' \n\t'
for parent in $( git log -1 --pretty=format:"%p" ${commit} )
do
IFS=$'\n\t'
parent_result="$( TZ=UTC git log --date=iso-local --pretty=format:"parents: %<(24)%pcommit: %<(10)%h%<(30)%an%<(26)%ad%s" HEAD | grep "$parent\|$commit" )"
if [[ ${#parent_result} -gt 0 ]]
then
for i in ${parent_result[@]}
do
parents+=( "${i}" )
done
else
parents+=( "<parent ${parent} is also orphaned>" )
fi
done
IFS=$'\n\t'
# this is super hacky
for line in ${parents[@]}
do
printf "%s\n" ${line}
done
done
IFS=$OLDIFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment