Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can a Git commit have multiple tree objects?

Does a commit object always have exactly one tree object?

I can’t think of a scenario where it wouldn’t be the case but I also can’t see any documentation that explicitly states it.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Does a commit object always have exactly one [top-level] tree object?

Yes.

I can’t think of a scenario where it wouldn’t be the case but I also can’t see any documentation that explicitly states it.

It’s part of the design: without it, git rev-parse commit^{tree} would not have an unambiguous result.

One can envision a system related to Git in which commits can store multiple trees,1 but a number of design issues would need to be resolved first.


1I’ve thought about this in several contexts, including the "submodules are wrong, subtrees are better but need better support" one. I have not resolved everything. 😀

Note that the commit object is also required to have exactly one author and one committer line; git fsck will object to the commit if these are malformed.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading