JGit是一个Java Git库,用于取消暂存文件。

4

我无法正确地在JGit中重置(reset)。即,我可以将所有文件添加到索引(index)中,我可以通过以下命令从索引(index)中删除/重置(staging)/取消跟踪(unstage)其中一些文件,但并非所有文件都能正常工作。什么是在JGit中取消跟踪文件的正确方法?

repository.getIndex().remove(getWorkignDirectoryAsFile(), new File(getWorkignDirectoryAsFile(), fileName));
repository.getIndex().write();

此外,

你是否遇到了编译时或运行时错误? - Tyler
2个回答

4
您可以使用JGit的ResetCommand类从索引中删除文件:
ResetCommand reset = new Git(repository).reset();
reset.setRef(Constants.HEAD);
reset.addPath("foo.txt");
reset.call();

3

与普通的git reset命令相当的是

git.reset().setMode(ResetType.MIXED).call();

在这里,git 是一个 org.eclipse.jgit.api.Git 的实例,而 ResetType 指的是 org.eclipse.jgit.api.ResetCommand.ResetType


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接