> From: cemico <webmas...@cemico.de>

> thank you for your very detailed information.
> But i can't get it to work.

Try the following script.  It's not efficient, but if the man pages
are correct, if you give it a blob hash (the full hash), it will show
what file names it has in what commits.  Then for each commit, it will
show what refs have that commit as an ancestor.  And at the bottom, it
lists all the refs that (indirectly) point to the blob in question.

You have to clear out the reflogs yourself.

But that should give you enough information to make the blob
un-referenced and then "git gc --prune=now --aggressive" should be
able to remove it.

I suppose it could be improved by searching through the reflogs and
seeing which of them point to commits that contain the blob.

#! /bin/bash

# Find a given blob, given its hash.

BLOB="${1:?First argument is the blob hash.}"

# Temporary file name base.

# Make a copy of stdout, since we will be redirecting stdout within the script.
exec 3>&1

# Find the commits in which the blob exists.

# List all commits.
git rev-list --all |
while read COMMIT
    # COMMIT_ADDED records whether this commit hash has been stored or not.
    # List all files within the commit.
    git ls-tree --full-tree $COMMIT |
    while read MODE TYPE HASH NAME
        # If this file matches the blob, report it.
        if [ "$HASH" = "$BLOB" ]
            echo >&3 Commit $COMMIT Name "$NAME"
            if [ "$COMMIT_ADDED" = no ]
                # Send the commit onward.
                echo $COMMIT
            # Beware that the same blob may appear multiple times, so we
            # have to continue searching through this tree.
done >$T.commits

# Find the refs that lead to the commits.

# List all the refs.
git show-ref |
while read COMMIT REF
    # REF_ADDED records whether this ref has been stored or not.
    # List all the commits in the ref that contain the blob.
    git rev-list $REF |
    grep -f $T.commits |
    while read COMMIT
        echo >&3 Commit $COMMIT Ref "$REF"
        if [ "$REF_ADDED" = no ]
            # Send the ref onward.
            echo "$REF"
done >$T.refs

# Write out the refs.

sed <$T.refs -e 's/^/Ref /'

You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to