JGit稀疏结账不断添加文件

时间:2016-04-04 15:25:43

标签: java git jgit

在Java中,我与JGit一起使用远程存储库执行某些操作。但是,当我在以下版本之间顺序执行稀疏检出时:

checkout.
  setCreateBranch(false).
  setName(tag).
  addPath("server/scripts/").
  setStartPoint(tag);

保留最后一个结帐文件并添加新文件。只有当目录中的文件名不相同时才会发生这种情况。当以这种方式使用checkout命令时,我怎么能避免这种情况?

我考虑删除正在结帐的文件夹中的文件(在这种情况下是脚本),但是我不知道当文件&时它是否会带来冲突#39;已下载的' 具有相同的名称。

1 个答案:

答案 0 :(得分:1)

First note that setCreateBranch() is false by default, hence there is no need to explicitly call setCreateBranch( false ).

Furthermore, you cannot mix addPath() and setName() The JavaDoc for addPath() says:

If this option is set, neither the setCreateBranch(boolean) nor setName(String) option is considered. In other words, these options are exclusive.

However, I am not sure if the behavior that you see is correct. In doubt check with command-line git to see if it shows the same results and file a bug report if JGit differs.

To work around the orphan files, you can use the StatusCommand to manually delete all untracked files:

Status status = git.status().call();
for( String fileName : status.getUntracked() ) {
  // delete fileName
}