The low-level API you can use for this is TreeFormatter together with CommitBuilder.
An example of using this can be seen here. In this case, it constructs one new tree object with multiple subtrees.
In your case, you probably have to recursively walk the tree and create the new tree objects on the path to the changed file and insert them bottom up. For the rest of the tree, you can use the existing tree IDs and don't have to descend into them. I recommend looking into TreeWalk#setRecursive
and TreeWalk#setPostOrderTraversal
.
Another option would be to create an in-core DirCache, fill it with DirCacheEntries from the commit and your updated entry, and then call DirCache#writeTree
.