git/list[1] front-page[2] threads[3] people[4] search[5] about
 

how to remove unreachable objects?

From
Ddieter@schoen.or.at <dieter@schoen.or.at>
Date
Sep 19, 2011, 09:08 UTC
Message-ID
<20110919110831.ewq03vnqos4w8cs8@webmail.edis.at>
hi,
i am relatively new to git, and am currently trying to get used to it.

at the moment i am exploring how to remove unneeded objects, this should be possible with prune, gc and/or fsck. maybe i have not found the right combination or something in my understand is not correct.

this is my use case: i create a repository and produce several commits on master. then i go back to a certain tag and create a new branch, where i also commit. then i switch back to master and delete (-D) the other branch. it should now be unreachable from within git (to prove its existence, i remember a commit SHA1 on the dead branch). then i try to get rid of the unreachable objects with a series of prune, fsck and gc.

------------- schoen.d@ax:~/projects/gitFeatures$ cat mk_dead_end.sh #!/bin/sh

DEAD=dead_end
rm -rf $DEAD
mkdir $DEAD
cd $DEAD
git init
echo "first commit" > A
git add A
git commit -m "first commit"
git tag first_commit
echo "second commit" >> A
git add A
git commit -m "second commit"
git checkout first_commit
echo "commit in dead end" >> A
git add A
git commit -m "changed A in dead end"
git checkout -b $DEAD
dead_commit=`git log -1 --format="%H"`
git checkout master
git branch -D $DEAD
git show $dead_commit
git fsck --unreachable --full --verbose
git fsck --unreachable HEAD \
                    $(git for-each-ref --format="%(objectname)" refs/heads)
git fsck --lost-found
git prune -v $dead_commit
git prune $(git rev-parse --all)
git repack
git prune-packed
git gc --prune=now
git gc --aggressive
git show $dead_commit

------ if you look at the output of this script then you see that git knows that there are unreachable/dangling objects, but they remain.

thankful for any pointer, dieter

Next: Jeff King
Message 1 of 9 in “how to remove unreachable objects?”
  1. dieter@schoen.or.atSep 19, 2011
  2. Jeff KingSep 19, 2011
  3. Jeff KingSep 19, 2011
  4. Junio C HamanoSep 19, 2011
  5. Jeff KingSep 19, 2011
  6. Junio C HamanoSep 20, 2011
  7. Jeff KingSep 20, 2011
  8. Dieter SchönSep 24, 2011
  9. Andreas SchwabSep 19, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.