一个 JGit 初学者问题:
我使用 JGit 从存储库中读取文件 (BLOB) 并操作其内容。之后,我想将具有相同文件名的新内容作为新提交写回存储库。但是如何使用 JGit 提交新内容呢?
我的伪代码:
String gitUrl = "path/to/repository/.git";
Repository repository = new FileRepository(gitUrl);
String filename = "test/seppl.txt";
blobId = getIdOf(filename);
ObjectLoader object = repository.open(blobId, Constants.OBJ_BLOB);
ObjectStream is = object.openStream();
String newContent = processStream(is);
// How to commit the newContent in filename?
我是否必须将其写入文件并使用AddCommand和CommitCommandnewContent
提交该文件?或者我可以将字符串“on-the-fly”以相同的文件名写入存储库吗?
网络上是否有任何使用 JGit 提交的示例?