Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java jGit-如何将所有文件添加到临时区域_Java_Git_Jgit - Fatal编程技术网

Java jGit-如何将所有文件添加到临时区域

Java jGit-如何将所有文件添加到临时区域,java,git,jgit,Java,Git,Jgit,我尝试了很多方法用jGit克隆回购协议(它是有效的)。 然后,我在存储库中编写了一些归档文件,并尝试添加所有内容(agitadd*,gitadd-a或类似的内容)。。但它不起作用。简单文件不会添加到临时区域 我的代码如下: FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(new File(folder))

我尝试了很多方法用jGit克隆回购协议(它是有效的)。 然后,我在存储库中编写了一些归档文件,并尝试添加所有内容(a
gitadd*
gitadd-a
或类似的内容)。。但它不起作用。简单文件不会添加到临时区域

我的代码如下:

    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    Repository repository = builder.setGitDir(new File(folder))
            .readEnvironment().findGitDir().setup().build();
    CloneCommand clone = Git.cloneRepository();
    clone.setBare(false).setCloneAllBranches(true);
    clone.setDirectory(f).setURI("git@192.168.2.43:test.git");
    try {
        clone.call();
    } catch (GitAPIException e) {
        e.printStackTrace();
    }
    Files.write("testing it...", new File(folder + "/test2.txt"),
            Charsets.UTF_8);
    Git g = new Git(repository);
    g.add().addFilepattern("*").call();
我做错了什么? 谢谢


尝试使用addFilePattern(“.”)执行操作时出现异常:


调试此问题的一种简单方法是查看中的测试:

您将看到,为了添加所有文件,从不使用模式“
*
”,而是使用“
”。
它用于名为。。。(!)

例外情况:

Exception in thread "main" org.eclipse.jgit.errors.NoWorkTreeException: 
Bare Repository has neither a working tree, nor an index
非常明确:您需要在非裸回购中添加文件


请参阅以与您自己的克隆进行比较,并查看是否有任何差异。

可能是通配符,我刚刚阅读了添加命令的javadoc,看起来您发送目录名称是为了添加其内容,而不是通配符:

addFilepattern

public AddCommand addFilepattern(String filepattern)
参数:
filepattern
-从中添加内容的文件也是一个主要目录 可以指定名称(例如,要添加的目录
dir/file1
dir/file2
)来添加所有 目录中的文件
,以递归方式Fileglobs(例如
*.c
)还没有被删除
支持。

我遇到过一种情况,我必须将文件f1从当前目录移动到另一个名为“temp”的目录。移动文件后,调用git.add().addFilePattern(“.”).call()的行为很奇怪,因为git status会给出以下结果:

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   temp/f1.html

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    deleted:    f1.html
git status现在给出了预期结果:

renamed:    f1.hml -> temp/f1.html

但我将其克隆为非裸存储库。。。我不知道我该怎么做…哈哈,这很有效。我只需执行Git Git=cloneCmd.call(),并使用这个Git实例来管理这些事情。。。谢谢@voncgit.add().addFilepattern(“.”.call();是否不暂存已删除的文件file@swaheed我确实明白了:@swaheed将
git.add().addFilepattern(“sub”).setUpdate(true.call()工作得更好?()有完全相同的问题。。谢谢你!(仍不固定)
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   temp/f1.html

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    deleted:    f1.html
git.add().addFilepattern(".").call();
git.add().setUpdate(true).addFilepattern(".").call();
renamed:    f1.hml -> temp/f1.html