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

Re: How to find all the commits that comprise a branch?

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
May 30, 2012, 20:23 UTC
Message-ID
<CAMP44s0ZJG1aqe8z-fPfwU+oMNwSh=YjNA6mPiZ+Tdj2eBgpKQ@mail.gmail.com>
In-Reply-To
<7vaa0pzcvp.fsf@alter.siamese.dyndns.org>
On Wed, May 30, 2012 at 9:29 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 29 quoted lines
> Felipe Contreras <felipe.contreras@gmail.com> writes:
>
>> Hi,
>>
>> Basically what I want to do is:
>>
>>  % git log branch ^<any-other-branch>
>>
>> IOW; all the commits were 'git branch --contains' would show 'branch'
>> and nothing else.
>>
>> Is there any easy way to do that?
>
> There was "log blah --not --all --exclude-ref=refs/heads/blah"
> discussion a few months ago, but I do not think anything came out of
> it.
>
> This is a tangent, but it would be a good way to find out set of
> commits that you would lose and need to go to reflog to find if you
> were to delete the branch.
>
> It however is a poor definition for "commits that comprise a branch";
> I actually am not sure if the concept has a sensible definition.
>
> Let's think aloud with a few examples.
>
> You may be done with your "work" branch and merge it to "master".
> At that point, do you think you no longer have any commit that
> comprises your "work" branch?
That's right... no commits.
Show 8 quoted lines
> You could argue that "work" branch is no longer relevant because it
> is part of "master", and it is an understandable viewpoint.
>
> But imagine what happens when you find a bug in your "work" and want
> to fix it up by queuing a correction on your "work" branch (not
> directly on "master", because your "work" branch was forked from
> "maint" and you eventually want to merge it there as well).  Now, is
> the single fix-up commit the only commit that comprises your "work"?
Yes. On that branch.
Show 8 quoted lines
> Suppose you have 5-patch series in your "work" branch, two commits
> at the bottom of which are useful refactoring of existing code.  I
> fork from the second commit to take advantage of your refactoring to
> work on something entirely different.  These two branches now share
> the bottom two commits.  At this point, do you have only three
> remaining commits on your "work" branch?  Wouldn't we rather want to
> say that I am merely borrowing two commits from you and you still
> have 5 commits that is what your "work" branch consists of?

It depends; if your branch gets merged to master, then my work branch is comprised of 3 commits.

Of course it's debatable how to consider the commits that are contained in multiple branches, but it's clear that the commits that are only in one branch comprise that branch.

Either way, call them 'independent' or whatever you want, but the concept of "commits that are only in one branch" is clear, and it's useful to find this information.

Cheers.
-- 
Felipe Contreras
Previous: Junio C HamanoNext: Sitaram Chamarty
Message 3 of 5 in “How to find all the commits that comprise a branch?”
  1. Felipe ContrerasMay 30, 2012
  2. Junio C HamanoMay 30, 2012
  3. Felipe ContrerasMay 30, 2012
  4. Sitaram ChamartyMay 31, 2012
  5. Felipe ContrerasMay 31, 2012

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.