小编use*_*933的帖子

Jgit:Bare Repository既没有工作树,也没有索引

我在E中创建了一个目录,命名为gitrepo full path is(E:\ gitrepo)之后我用以下代码克隆了一个存储库

Git git=Git.cloneRepository()
                .setURI("samplelink.git")
                .setDirectory(new File("/E:/gitrepo"))
                .call();
Run Code Online (Sandbox Code Playgroud)

然后我用这段代码打开了一个存储库

public Repository openRepository() throws IOException {
    FileRepositoryBuilder builder = new FileRepositoryBuilder();

    Repository repository = builder.setGitDir(new File("/E:/gitrepo"))
            .readEnvironment() // scan environment GIT_* variables
            .findGitDir() // scan up the file system tree
            .build();
     log.info("Repository directory is {}", repository.getDirectory());

    return repository;
}
Run Code Online (Sandbox Code Playgroud)

一切正常,直到这里我试图在这个本地存储库中添加一个文件

Repository repo = openRepository();
            Git git = new Git(repo);
            File myfile = new File(repo.getDirectory()/*.getParent()*/, "testfile");
            if (!myfile.createNewFile()) {
                throw new IOException("Could not create file " + myfile);
            } …
Run Code Online (Sandbox Code Playgroud)

java git jgit

3
推荐指数
1
解决办法
1552
查看次数

标签 统计

git ×1

java ×1

jgit ×1