git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* How do I get rid of unneeded objects?
@ 2019-01-18 13:39 Steve Keller
  2019-01-18 22:40 ` Eric Wong
  0 siblings, 1 reply; 3+ messages in thread
From: Steve Keller @ 2019-01-18 13:39 UTC (permalink / raw)
  To: git

After deleting a branch or amending a commit I still have orphaned
objects in the repository:

    $ mkdir repo; cd repo
    $ git init
    $ date > foo; git add foo; git commit -mmsg1                                        
    $ date > foo; git add foo; git commit -mmsg2                                        
    $ git checkout -b branch-1 HEAD^
    Switched to a new branch 'branch-1'
    $ git commit --allow-empty -mbranch-1
    [branch-1 84cfad2] branch-1
    $ git log --oneline
    84cfad2 branch-1
    09fdcb1 msg1
    $ find .git/objects/ -type f | sort | nl
    1  .git/objects/09/fdcb1cb7d5642874bd642ce5685ac0bebd116c
    2  .git/objects/41/d9ceb271c5e72f8a94a38dc4852ab501566bd1
    3  .git/objects/4f/c6596065dd08ebc62ce0728e2407d58dbde7e1
    4  .git/objects/5f/c4d7af12460d774be720f8761da0be2595404d
    5  .git/objects/84/cfad2cea2ae3f7a67530d5c596853f656e68d9
    6  .git/objects/a1/5faea60776cd537c4ef527f08caff48ff6c86b
    7  .git/objects/c8/c0278da7cf96d86c5881f3884b5015deee7113

These objects are 2 files, 2 trees, and 3 commits.  If now delete the
branch again, I'd like to have the unneeded commit deleted, but:

    $ git checkout master
    Switched to branch 'master'
    $ git branch -D branch-1
    Deleted branch branch-1 (was 84cfad2).
    $ git reflog expire --all
    $ git prune
    $ find .git/objects/ -type f | sort | nl
    1  .git/objects/09/fdcb1cb7d5642874bd642ce5685ac0bebd116c
    2  .git/objects/41/d9ceb271c5e72f8a94a38dc4852ab501566bd1
    3  .git/objects/4f/c6596065dd08ebc62ce0728e2407d58dbde7e1
    4  .git/objects/5f/c4d7af12460d774be720f8761da0be2595404d
    5  .git/objects/84/cfad2cea2ae3f7a67530d5c596853f656e68d9   <-- [1]
    6  .git/objects/a1/5faea60776cd537c4ef527f08caff48ff6c86b
    7  .git/objects/c8/c0278da7cf96d86c5881f3884b5015deee7113

Why is [1] not deleted?  It seems reflog still knows about the deleted
branch, and probably this is the reason git keeps the referenced
commit:

    $ git reflog
    c8c0278 HEAD@{0}: checkout: moving from branch-1 to master
    84cfad2 HEAD@{1}: commit: branch-1
    09fdcb1 HEAD@{2}: checkout: moving from master to branch-1
    c8c0278 HEAD@{3}: commit: msg2
    09fdcb1 HEAD@{4}: commit (initial): msg1

Also, git gc, mentioned in the man page for git-reflog does not help.
And I see similar things when amending a commit, where the old commit
object is kept.  How can one get rid of this?

Steve

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How do I get rid of unneeded objects?
  2019-01-18 13:39 How do I get rid of unneeded objects? Steve Keller
@ 2019-01-18 22:40 ` Eric Wong
  2019-01-19  7:38   ` Kevin Daudt
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Wong @ 2019-01-18 22:40 UTC (permalink / raw)
  To: Steve Keller; +Cc: git

Steve Keller <keller.steve@gmx.de> wrote:
>     $ git reflog expire --all

I've never used "git reflog" directly, but I think you need to
add "--expire=all" to cover all time.  "--all" is only for all
branches, so you need "--expire=<time>" is for a time range.

Fwiw, I use a single command:

	git -c gc.reflogExpire=now gc --prune=all

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How do I get rid of unneeded objects?
  2019-01-18 22:40 ` Eric Wong
@ 2019-01-19  7:38   ` Kevin Daudt
  0 siblings, 0 replies; 3+ messages in thread
From: Kevin Daudt @ 2019-01-19  7:38 UTC (permalink / raw)
  To: Eric Wong; +Cc: Steve Keller, git

On Fri, Jan 18, 2019 at 10:40:55PM +0000, Eric Wong wrote:
> Steve Keller <keller.steve@gmx.de> wrote:
> >     $ git reflog expire --all
> 
> I've never used "git reflog" directly, but I think you need to
> add "--expire=all" to cover all time.  "--all" is only for all
> branches, so you need "--expire=<time>" is for a time range.
> 
> Fwiw, I use a single command:
> 
> 	git -c gc.reflogExpire=now gc --prune=all

Instead of --expire, you could also use --expire-unreachable, so that
you don't get rid of your entire reflog.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-01-19  7:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-18 13:39 How do I get rid of unneeded objects? Steve Keller
2019-01-18 22:40 ` Eric Wong
2019-01-19  7:38   ` Kevin Daudt

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).