使用JGit提交字符串

Son*_*123 8 java jgit

一个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?
Run Code Online (Sandbox Code Playgroud)

我是否必须将newContent文件写入文件并使用AddCommandCommitCommand提交此文件?或者我可以使用相同的文件名将"即时"字符串写入存储库吗?

Web中是否有任何例子如何使用JGit进行提交?

Vin*_*nce 6

我认为没有其他方法可以提交任何数据而不是使用CommitCommand(合并或非常具体的此类操作除外).

所以,是的,您应该对文件进行任何更改,然后添加并提交它(使用API​​中的AddCommand和CommitCommand).