Skip to contentSkip to conversation

Commit ID of a branch

DISCUSSION Guillermo 3 participants 5 messages Jun 15, 2016 1 message not in the archive

lore
Share & tools
lore

Guillermo

author
#0 lore raw

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

#1 lore raw
Quoted 12 lines · Guillermo

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

Quoted 5 lines

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

#3 lore raw
In reply to Guillermo
Quoted 7 lines · Guillermo

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:

Quoted 7 lines

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.

#2 lore raw
In reply to Chris Packham

Thank you!

Quoted 31 lines · Chris Packham
Quoted 12 lines · Guillermo

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

Quoted 5 lines

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

Signature · 1 line
Guillermo