threads / discuss / 30659

How to find all the commits that comprise a branch?

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

## tl;dr

5 messages between May 30, 2012 and May 31, 2012.

replies: 4people: 3as markdown or json

Felipe Contreras· May 30, 2012, 17:39 UTC · lore
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?
Cheers.
-- 
Felipe Contreras
Junio C Hamano· May 30, 2012, 19:29 UTC · re: Felipe Contreras · lore

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

Felipe Contreras <felipe.contreras@gmail.com> writes:
Show 10 quoted lines
> 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?

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"?

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?

Felipe Contreras· May 30, 2012, 20:23 UTC · re: Junio C Hamano · lore

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

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
Sitaram Chamarty· May 31, 2012, 03:22 UTC · re: Felipe Contreras · lore

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

On Wed, May 30, 2012 at 11:09 PM, Felipe Contreras <felipe.contreras@gmail.com> wrote:

Show 8 quoted lines
> 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.

I have a script called "otb" (only this branch, I guess; I tend to use crappily short names for stuff I don't make public!) that looks like this:

#!/bin/bash

m=$(git rev-parse HEAD) n=$(git rev-parse --branches | grep -v $m) git log --oneline $m --not $n

I think that fits your description, but it's not *one* command.
Show 10 quoted lines
> Is there any easy way to do that?
>
> Cheers.
>
> --
> Felipe Contreras
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
-- 
Sitaram
Felipe Contreras· May 31, 2012, 12:56 UTC · re: Sitaram Chamarty · lore

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

On Thu, May 31, 2012 at 5:22 AM, Sitaram Chamarty <sitaramc@gmail.com> wrote:
Show 22 quoted lines
> On Wed, May 30, 2012 at 11:09 PM, Felipe Contreras
> <felipe.contreras@gmail.com> wrote:
>> 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.
>
> I have a script called "otb" (only this branch, I guess; I tend to use
> crappily short names for stuff I don't make public!) that looks like
> this:
>
> #!/bin/bash
>
> m=$(git rev-parse HEAD)
> n=$(git rev-parse --branches | grep -v $m)
> git log --oneline $m --not $n
>
> I think that fits your description, but it's not *one* command.

Yeap, I was thinking on doing something along those lines... but hoped there was a single command for it.

Cheers.
-- 
Felipe Contreras

← back to recent threads