{"thread":{"id":"50261","subject":"How do I get rid of unneeded objects?","startedAt":"2019-01-18T13:39:55Z","lastAt":"2019-01-19T07:45:27Z","messageCount":3,"participants":["Steve Keller","Eric Wong","Kevin Daudt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"367095","messageId":"trinity-02f2f7de-850d-4ad6-b709-86b7914cd81f-1547818792471@3c-app-gmx-bs22","threadId":"50261","inReplyTo":null,"subject":"How do I get rid of unneeded objects?","fromName":"Steve Keller","fromEmail":"keller.steve@gmx.de","sentAt":"2019-01-18T13:39:52Z","receivedAt":"2019-01-18T13:39:55Z","isPatch":false,"sender":{"key":"keller.steve@gmx.de","avatar":null},"body":"After deleting a branch or amending a commit I still have orphaned\nobjects in the repository:\n\n    $ mkdir repo; cd repo\n    $ git init\n    $ date > foo; git add foo; git commit -mmsg1                                        \n    $ date > foo; git add foo; git commit -mmsg2                                        \n    $ git checkout -b branch-1 HEAD^\n    Switched to a new branch 'branch-1'\n    $ git commit --allow-empty -mbranch-1\n    [branch-1 84cfad2] branch-1\n    $ git log --oneline\n    84cfad2 branch-1\n    09fdcb1 msg1\n    $ find .git/objects/ -type f | sort | nl\n    1  .git/objects/09/fdcb1cb7d5642874bd642ce5685ac0bebd116c\n    2  .git/objects/41/d9ceb271c5e72f8a94a38dc4852ab501566bd1\n    3  .git/objects/4f/c6596065dd08ebc62ce0728e2407d58dbde7e1\n    4  .git/objects/5f/c4d7af12460d774be720f8761da0be2595404d\n    5  .git/objects/84/cfad2cea2ae3f7a67530d5c596853f656e68d9\n    6  .git/objects/a1/5faea60776cd537c4ef527f08caff48ff6c86b\n    7  .git/objects/c8/c0278da7cf96d86c5881f3884b5015deee7113\n\nThese objects are 2 files, 2 trees, and 3 commits.  If now delete the\nbranch again, I'd like to have the unneeded commit deleted, but:\n\n    $ git checkout master\n    Switched to branch 'master'\n    $ git branch -D branch-1\n    Deleted branch branch-1 (was 84cfad2).\n    $ git reflog expire --all\n    $ git prune\n    $ find .git/objects/ -type f | sort | nl\n    1  .git/objects/09/fdcb1cb7d5642874bd642ce5685ac0bebd116c\n    2  .git/objects/41/d9ceb271c5e72f8a94a38dc4852ab501566bd1\n    3  .git/objects/4f/c6596065dd08ebc62ce0728e2407d58dbde7e1\n    4  .git/objects/5f/c4d7af12460d774be720f8761da0be2595404d\n    5  .git/objects/84/cfad2cea2ae3f7a67530d5c596853f656e68d9   <-- [1]\n    6  .git/objects/a1/5faea60776cd537c4ef527f08caff48ff6c86b\n    7  .git/objects/c8/c0278da7cf96d86c5881f3884b5015deee7113\n\nWhy is [1] not deleted?  It seems reflog still knows about the deleted\nbranch, and probably this is the reason git keeps the referenced\ncommit:\n\n    $ git reflog\n    c8c0278 HEAD@{0}: checkout: moving from branch-1 to master\n    84cfad2 HEAD@{1}: commit: branch-1\n    09fdcb1 HEAD@{2}: checkout: moving from master to branch-1\n    c8c0278 HEAD@{3}: commit: msg2\n    09fdcb1 HEAD@{4}: commit (initial): msg1\n\nAlso, git gc, mentioned in the man page for git-reflog does not help.\nAnd I see similar things when amending a commit, where the old commit\nobject is kept.  How can one get rid of this?\n\nSteve\n"},{"id":"367157","messageId":"20190118224055.zpsz63b3gaxtwscu@dcvr","threadId":"50261","inReplyTo":"trinity-02f2f7de-850d-4ad6-b709-86b7914cd81f-1547818792471@3c-app-gmx-bs22","subject":"Re: How do I get rid of unneeded objects?","fromName":"Eric Wong","fromEmail":"e@80x24.org","sentAt":"2019-01-18T22:40:55Z","receivedAt":"2019-01-18T22:40:56Z","isPatch":false,"sender":{"key":"e@80x24.org","avatar":null},"body":"Steve Keller <keller.steve@gmx.de> wrote:\n>     $ git reflog expire --all\n\nI've never used \"git reflog\" directly, but I think you need to\nadd \"--expire=all\" to cover all time.  \"--all\" is only for all\nbranches, so you need \"--expire=<time>\" is for a time range.\n\nFwiw, I use a single command:\n\n\tgit -c gc.reflogExpire=now gc --prune=all\n"},{"id":"367171","messageId":"20190119073808.GA14639@alpha","threadId":"50261","inReplyTo":"20190118224055.zpsz63b3gaxtwscu@dcvr","subject":"Re: How do I get rid of unneeded objects?","fromName":"Kevin Daudt","fromEmail":"me@ikke.info","sentAt":"2019-01-19T07:38:08Z","receivedAt":"2019-01-19T07:45:27Z","isPatch":false,"sender":{"key":"me@ikke.info","avatar":"https://avatars.githubusercontent.com/u/135698?v=4"},"body":"On Fri, Jan 18, 2019 at 10:40:55PM +0000, Eric Wong wrote:\n> Steve Keller <keller.steve@gmx.de> wrote:\n> >     $ git reflog expire --all\n> \n> I've never used \"git reflog\" directly, but I think you need to\n> add \"--expire=all\" to cover all time.  \"--all\" is only for all\n> branches, so you need \"--expire=<time>\" is for a time range.\n> \n> Fwiw, I use a single command:\n> \n> \tgit -c gc.reflogExpire=now gc --prune=all\n\nInstead of --expire, you could also use --expire-unreachable, so that\nyou don't get rid of your entire reflog.\n"}]}