3

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.

3
  • Why don't you ls-tree a commit and see? Commented Apr 14, 2022 at 11:21
  • It's like asking, if a man can have two wives? There's no objective limitation, it's just not always designed to be this way Commented Apr 14, 2022 at 11:22
  • 1
    @AlexeyLarionov: As someone who lived in Utah for a while, I'll note that actually it's the bordering states that have more of the FLDS families. 😀 Commented Apr 14, 2022 at 11:27

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.