Last active
June 28, 2023 19:37
-
-
Save capnslipp/2656868 to your computer and use it in GitHub Desktop.
Lost & Found for Git: tag all dangling commits, for those wonderful “oh shit” moments (and cleanup those tags after recovered the lost path)
This file contains 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 | |
# Tags all dangling commits in a Git repo (for the wonderful “oh shit” moments). | |
# @from: https://gist.github.com/capnslipp/2656868 | |
git fsck --lost-found #--no-reflogs --full --root --cache --tags --unreachable | |
find '.git/lost-found/commit' -type f | while read i; do | |
commit_sha=`cat "$i"` | |
git tag -f "git-lf/commit/$commit_sha" $commit_sha | |
done | |
if [ -f '.git/lost-found/other' ]; then | |
find '.git/lost-found/other' -type f | while read i; do | |
commit_sha=`cat "$i"` | |
echo "git tag -f \"git-lf/other/$commit_sha\" $commit_sha" | |
done | |
fi | |
# @note: I'm not sure what to do with “other dangling objects” in .git/lost-found/commit; they tend to report “fatal: bad object” when passed to git-show. |
This file contains 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 | |
# Removes all “git-lf/” prefixed tags added by git-lf. | |
# @from: https://gist.github.com/slippyd/2656868 | |
git tag --list 'git-lf/*' | xargs git tag -d | |
# This is safe to do, right? | |
rm -rf .git/lost-found |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment