Git fetch没有按预期工作

时间:2018-06-03 15:49:09

标签: git jgit

我正在使用JGit 我在远程存储库(master)中添加文件hello.docx 当我从代码git status显示git fetch时显示

On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

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

        deleted:   project documentations/SAT/hello.docx

这是错误的行为git status应该说是这样的

On branch master
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)

如果我删除远程存储库(master)

中的文件hello.docx

从代码git status执行git fetch后显示

On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

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

        new file:   project documentations/SAT/hello.docx

git fetch的行为不正确 git fetch在gitbash上工作正常但在代码

中没有
GitOpenRepository open = new GitOpenRepository();
  try (Repository repository = open.openRepository();) {
                      try (Git git = new Git(repository)) {
                          log.info("what is in repository {}",repository.getDirectory());
                            String branch =repository.getFullBranch();

                            RefSpec spec = new RefSpec().setSourceDestination("refs/heads/master", "refs/heads/master");
                            FetchCommand command = git.fetch();
                            command.setRefSpecs(spec);
                            FetchResult result = null;
                            try {
                                result = command.call();
                            } catch (Throwable e) {
                                throw new RuntimeException(String.format(
                                        "Failed to fetch from [%s] to [%s]",
                                        branch,
                                        branch), e);
                            }

                            log.info("result.getMessages() ",result.getMessages()); ;
                            getStatus();
}
                  catch(Exception i){
                      System.out.println("exception"+i);
                  }

0 个答案:

没有答案