threads / discuss / 24757

Commit ID of a branch

Subject: Commit ID of a branch

## tl;dr

5 messages between Aug 16, 2010 and Aug 17, 2010.

replies: 4people: 3as markdown or json

Guillermo· Aug 16, 2010, 21:19 UTC · lore
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· Aug 16, 2010, 21:50 UTC · re: Guillermo · lore

Re: Commit ID of a branch

On Mon, Aug 16, 2010 at 21:19, Guillermo <guillermog@tricuspide.com> wrote:
Show 14 quoted lines
> 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.
Chris Packham· Aug 16, 2010, 23:43 UTC · re: Guillermo · lore

Re: Commit ID of a branch

On 16/08/10 14:19, Guillermo wrote:
Show 17 quoted lines
> 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· Aug 17, 2010, 12:35 UTC · re: Chris Packham · lore

Re: Commit ID of a branch

Thank you!
On 17 August 2010 01:43, Chris Packham <judge.packham@gmail.com> wrote:
Show 31 quoted lines
> 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
Guillermo Gonzalez· Aug 16, 2010, 22:32 UTC · lore

Re: Commit ID of a branch

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

← back to recent threads