Subject: Re: ephemeral-branches instead of detached-head?

From: Sitaram Chamarty <[email-masked]>
Date: Wed, 14 Aug 2013 05:34:56 +0530

On 08/13/2013 10:19 PM, Junio C Hamano wrote:
> Duy Nguyen <[email-masked]> writes:
> 
>> On Mon, Aug 12, 2013 at 3:37 PM, David Jeske <[email-masked]> wrote:
>>> Is there currently any way to say "hey, git, show me what commits are
>>> dangling that might be lost in the reflog?"
>>
>> How do you define dangling commits? When you do "git commit --amend",
>> the current commit will become dangling (in the sense that it's not
>> referred by any ref, but the commit exists) and those are just noise
>> in my opinion.
> 
> "fsck lost-and-found" would be one way.  It would be nice if we had
> something like (note: the following will _NOT_ work)
> 
> 	git log -g HEAD --not --branches
> 
> to say "walk the reflog of HEAD, but exclude anything that can be
> reached from the tips of branches".

I've been using the following 3 aliases for some time now, to find
various dangling stuff.  The middle one (d1) seems to do approximately
what you want, but will probably fail on repos with lots of activity
when the command line length limit is (b)reached.

    # all stashed entries (since they don't chain)
    sk = !gitk --date-order $(git stash list | cut -d: -f1) --not --branches --tags --remotes
    # all reflog entries that are not on a branch, tag, or remote
    d1 = !gitk --date-order $(git log -g --pretty=%H) --not --branches --tags --remotes
    # all dangling commits not on a branch, tag, or remote
    d2 = !gitk --date-order $(git fsck | grep "dangling.commit" | cut -f3 -d' ') --not --branches --tags --remotes

(Apologies if something like this was already said; I was not following
the discussion closely enough to notice)