【问题标题】:JGit Java Git Library Unstaging FilesJGit Java Git 库取消暂存文件
【发布时间】:2011-06-15 18:21:04
【问题描述】:

我无法重置以在 JGit 中正常工作。 IE。我可以将所有文件添加到索引中,我可以通过以下命令从索引中删除/重置/取消暂存其中的一些文件,但它不适用于所有文件。在 JGit 中取消暂存文件的正确方法是什么?

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

还有

【问题讨论】:

  • 您是否遇到任何编译时或运行时错误?

标签: java git jgit


【解决方案1】:

您可以使用 JGit ResetCommand 类从索引中删除文件:

ResetCommand reset = new Git(repository).reset();
reset.setRef(Constants.HEAD);
reset.addPath("foo.txt");
reset.call();

【讨论】:

    【解决方案2】:

    相当于一个普通的git reset 命令是

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

    其中gitorg.eclipse.jgit.api.Git 的一个实例,ResetType 指的是org.eclipse.jgit.api.ResetCommand.ResetType

    【讨论】:

      猜你喜欢
      • 2020-11-14
      • 2015-06-19
      • 1970-01-01
      • 2016-01-22
      • 2012-03-24
      • 2014-08-15
      • 2016-07-05
      • 2021-03-16
      • 2021-11-18
      相关资源
      最近更新 更多