问题描述
我需要使用JGit将现有的git存储库克隆到InMemoryRepository
中,更改文件的内容,然后将所做的更改推回到远程存储库中.
I need to clone an existing git repository into an InMemoryRepository
, using JGit, change a file's content and push the changes back to the remote repository.
我找不到将存储库克隆到内存中存储库的任何示例.
I couldn't find any examples of cloning a repository into an in-memory repository.
我尝试过:
InMemoryRepository.Builder builder = new InMemoryRepository.Builder();
InMemoryRepository inm = builder.build();
Git.cloneRepository().setURI("git@[github_url].git").setDirectory(inm.getDirectory()).call();
哪个导致了错误:
我检查了InMemoryRepository.Builder
和Repository
类的配置选项,但没有发现有用的东西.
I checked the configuration options for InMemoryRepository.Builder
and Repository
classes, but haven't found anything useful.
该怎么办?然后,从内存中存储库更改文件内容并将其推送到github是否存在任何问题?
How can it be done? And after that, is there any problem with changing a file's content and pushing it to github, all from the in-memory repository?
推荐答案
CloneCommand
将始终创建基于文件的存储库.帖子中创建InMemoryRepository
的行对clone命令无效.
The CloneCommand
will always create a file-based repository. The lines from your post that create an InMemoryRepository
have no effect on the clone command.
如果您只需要存储库进行更改并推送结果,我建议克隆到一个临时位置.
I suggest to clone into a temporary location if you only need the repository to make a change and push the result.
例如:
Git.cloneRepository().setURI( ... ).setDirectory( new File("/path/to/empty/dir" ) ).call();
JGit中的InMemoryRepository
仍然需要一个工作目录来执行诸如检出等操作.仅将通常在.git
目录中找到的对象数据库存储在内存中
An InMemoryRepository
in JGit still requires a work directory for operations like checkout, etc. Only the object database which is usually found in the .git
directory is stored in memory
这篇关于使用JGit将git仓库克隆到InMemoryRepository中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!