# Commit ID of a branch

5 messages from 2010-08-16 to 2010-08-17. Participants: Guillermo, Ævar Arnfjörð Bjarmason, Guillermo Gonzalez, Chris Packham.
Thread: https://gitlist.dev/t/24757

## Guillermo, 2010-08-16 21:19

Subject: Commit ID of a branch
Message-ID: <loom.20100816T231539-211@post.gmane.org>
URL: https://gitlist.dev/e/loom.20100816T231539-211%40post.gmane.org

```
Hello,

I want to write a script what checks in all my projects which is the submodule
commit that is registered in every git repo.

Lets say we have the following structure:

project1
- submodule1
project2
- submodule1

I want to find out what file within the .git dir of every project contains the
proper submodule Commit ID that should be checkout with git submodule update.

Regards,
Guillermo

```

## Ævar Arnfjörð Bjarmason, 2010-08-16 21:50

Subject: Re: Commit ID of a branch
Message-ID: <AANLkTik0FFHCdMTa_MDpdg-df2fAkpKgyVyRUCuhZ5=c@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTik0FFHCdMTa_MDpdg-df2fAkpKgyVyRUCuhZ5%3Dc%40mail.gmail.com
In-Reply-To: <loom.20100816T231539-211@post.gmane.org>

```
On Mon, Aug 16, 2010 at 21:19, Guillermo <guillermog@tricuspide.com> wrote:
> Hello,
>
> I want to write a script what checks in all my projects which is the submodule
> commit that is registered in every git repo.
>
> Lets say we have the following structure:
>
> project1
> - submodule1
> project2
> - submodule1
>
> I want to find out what file within the .git dir of every project contains the
> proper submodule Commit ID that should be checkout with git submodule update.

That ID is stored in a tree object, See e.g. git-ls-tree for how to get it.

```

## Guillermo Gonzalez, 2010-08-16 22:32

Subject: Re: Commit ID of a branch
Message-ID: <AANLkTikZo5sZogpmA-xjV11HvUp-qtigedVFg1x5FC52@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikZo5sZogpmA-xjV11HvUp-qtigedVFg1x5FC52%40mail.gmail.com
In-Reply-To: <AANLkTikD3pmMx1epkp9RdaDBCw3hfVg5RGSCai2UEvaE@mail.gmail.com>

```
Ooops sorry I just dont seem to understand how to get it.

While Ive user git for two years now.. I just some have limited
understanding of the internals.

Thanks

```

## Chris Packham, 2010-08-16 23:43

Subject: Re: Commit ID of a branch
Message-ID: <4C69CD2C.9000700@gmail.com>
URL: https://gitlist.dev/e/4C69CD2C.9000700%40gmail.com
In-Reply-To: <loom.20100816T231539-211@post.gmane.org>

```
On 16/08/10 14:19, Guillermo wrote:
> Hello,
> 
> I want to write a script what checks in all my projects which is the submodule
> commit that is registered in every git repo.
> 
> Lets say we have the following structure:
> 
> project1
> - submodule1
> project2
> - submodule1
> 
> I want to find out what file within the .git dir of every project contains the
> proper submodule Commit ID that should be checkout with git submodule update.
> 
> Regards,
> Guillermo

If I understand your question correctly, what you want is

  git ls-tree HEAD submodule1

Which will give you the sha1 of the commit in the submodule your project
should be pointing to. We use this in various scripts at work.

It is also possible to get this information (and more) from a slightly
friendlier submodule command if you want it for non-script usage.

  git submodule status

```

## Guillermo Gonzalez, 2010-08-17 12:35

Subject: Re: Commit ID of a branch
Message-ID: <AANLkTikdVh9-60UjJW3vOp7jPA8_D_L+GqQ-9B5tcVeB@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikdVh9-60UjJW3vOp7jPA8_D_L%2BGqQ-9B5tcVeB%40mail.gmail.com
In-Reply-To: <4C69CD2C.9000700@gmail.com>

```
Thank you!

On 17 August 2010 01:43, Chris Packham <judge.packham@gmail.com> wrote:
> On 16/08/10 14:19, Guillermo wrote:
>> Hello,
>>
>> I want to write a script what checks in all my projects which is the submodule
>> commit that is registered in every git repo.
>>
>> Lets say we have the following structure:
>>
>> project1
>> - submodule1
>> project2
>> - submodule1
>>
>> I want to find out what file within the .git dir of every project contains the
>> proper submodule Commit ID that should be checkout with git submodule update.
>>
>> Regards,
>> Guillermo
>
> If I understand your question correctly, what you want is
>
>  git ls-tree HEAD submodule1
>
> Which will give you the sha1 of the commit in the submodule your project
> should be pointing to. We use this in various scripts at work.
>
> It is also possible to get this information (and more) from a slightly
> friendlier submodule command if you want it for non-script usage.
>
>  git submodule status
>



-- 
Guillermo

```
