使用JGit将git仓库克隆到InMemoryRepository中 [英] Clone a git repository into an InMemoryRepository with JGit

查看:134
本文介绍了使用JGit将git仓库克隆到InMemoryRepository中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用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();  

哪个导致了错误:

'目标路径".git"已存在且不为空 目录".

'Destination path ".git" already exists and is not an empty directory'.

我检查了InMemoryRepository.BuilderRepository类的配置选项,但没有发现有用的东西.

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中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆