Created
July 18, 2022 08:41
-
-
Save manuelnaranjo/e6d2dba90fe47c3e01e28b2e2287e5f3 to your computer and use it in GitHub Desktop.
Fix broken repo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
function clean_invalid_refs() { | |
INVALID_SHAS=`git for-each-ref --format="%(objectname)" | sort | uniq | git cat-file --batch-check | grep missing | cut -d' ' -f 1`; | |
if [ -z "${INVALID_SHAS}" ]; then | |
echo "Nothing to cleanup" > /dev/stderr | |
return | |
fi | |
REGEX=$(echo "$INVALID_SHAS" | paste -sd '|') | |
REFS=`git for-each-ref --format="%(refname) %(objectname)" | grep -E $REGEX | cut -d' ' -f 1` | |
for ref in $REFS; do | |
echo "deleting ${ref}" | |
git update-ref -d ${ref} | |
done | |
} | |
clean_invalid_refs | |
git fetch "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment