# How to find all the commits that comprise a branch?

5 messages from 2012-05-30 to 2012-05-31. Participants: Felipe Contreras, Junio C Hamano, Sitaram Chamarty.
Thread: https://gitlist.dev/t/30659

## Felipe Contreras, 2012-05-30 17:39

Subject: How to find all the commits that comprise a branch?
Message-ID: <CAMP44s2kEMK8ik2NTiP4uiN4FPWFNYNJfY5qh5QE_hRH2AiNYA@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s2kEMK8ik2NTiP4uiN4FPWFNYNJfY5qh5QE_hRH2AiNYA%40mail.gmail.com

```
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, 2012-05-30 19:29

Subject: Re: How to find all the commits that comprise a branch?
Message-ID: <7vaa0pzcvp.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vaa0pzcvp.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CAMP44s2kEMK8ik2NTiP4uiN4FPWFNYNJfY5qh5QE_hRH2AiNYA@mail.gmail.com>

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

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, 2012-05-30 20:23

Subject: Re: How to find all the commits that comprise a branch?
Message-ID: <CAMP44s0ZJG1aqe8z-fPfwU+oMNwSh=YjNA6mPiZ+Tdj2eBgpKQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s0ZJG1aqe8z-fPfwU%2BoMNwSh%3DYjNA6mPiZ%2BTdj2eBgpKQ%40mail.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:
> 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.

> 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.

> 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, 2012-05-31 03:22

Subject: Re: How to find all the commits that comprise a branch?
Message-ID: <CAMK1S_i5-ALrMA+iJ1Q4R5FuVbjVdFLfxKoEF4BVHERHSzmjeg@mail.gmail.com>
URL: https://gitlist.dev/e/CAMK1S_i5-ALrMA%2BiJ1Q4R5FuVbjVdFLfxKoEF4BVHERHSzmjeg%40mail.gmail.com
In-Reply-To: <CAMP44s2kEMK8ik2NTiP4uiN4FPWFNYNJfY5qh5QE_hRH2AiNYA@mail.gmail.com>

```
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.

> 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, 2012-05-31 12:56

Subject: Re: How to find all the commits that comprise a branch?
Message-ID: <CAMP44s3Fn3nai3TqCpYRxyV=3=d3vm5aPd-VgZWpVXb4qC8W8Q@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s3Fn3nai3TqCpYRxyV%3D3%3Dd3vm5aPd-VgZWpVXb4qC8W8Q%40mail.gmail.com
In-Reply-To: <CAMK1S_i5-ALrMA+iJ1Q4R5FuVbjVdFLfxKoEF4BVHERHSzmjeg@mail.gmail.com>

```
On Thu, May 31, 2012 at 5:22 AM, Sitaram Chamarty <sitaramc@gmail.com> wrote:
> 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

```
