Clone a git repository into an InMemoryRepository with JGit

后端 未结 3 1985
温柔的废话
温柔的废话 2020-12-06 07:34

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.<

3条回答
  •  没有蜡笔的小新
    2020-12-06 07:39

    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.

    For example:

    Git.cloneRepository().setURI( ... ).setDirectory( new File("/path/to/empty/dir" ) ).call();  
    

    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

提交回复
热议问题