Java 自定义git push ant任务在JGit中不起作用

Java 自定义git push ant任务在JGit中不起作用,java,git,ant,jgit,Java,Git,Ant,Jgit,我正在尝试使用JGit完成我的自定义git push ant任务,它应该将指定的分支推送到远程存储库,但它似乎不起作用 以下是我的任务Java代码: public void setRepository(String repository) { this.repository = repository; } public void setPassword(String password) { this.password = password; }

我正在尝试使用JGit完成我的自定义git push ant任务,它应该将指定的分支推送到远程存储库,但它似乎不起作用

以下是我的任务Java代码:

  public void setRepository(String repository) {
      this.repository = repository;
  }
  public void setPassword(String password) {
      this.password = password;
  }   
  public void setUsername(String username) {
      this.username = username;
  }     
  public void setUri(String uri) {
      this.uri = uri;
  }     
  public void setBranch(String branch) {
      this.branch = branch;
  }


  public void execute() throws BuildException {
    try{

        Git git = Git.open(new File(repository));            
        CredentialsProvider cp = new UsernamePasswordCredentialsProvider(username, password);
        RefSpec spec = new RefSpec("refs/heads/" + branch + ":refs/heads/" + branch);

        PushCommand pushCommand = git.push();
         pushCommand.setCredentialsProvider(cp).setRemote(uri).setForce(true).setRefSpecs(spec).call();


    }catch (Exception e) {  
        log(e, Project.MSG_ERR);
        throw new BuildException("Could not push repository: " + e.getMessage(), e);

    }
下面是Apache ant构建文件中的一行:

<gitpush 
    repository="./myrepo" 
    uri="ssh://username@host.com/repo/project.git" 
    branch="mybranch" 
    password="77CJr2xr" />


我创建了一个新分支并尝试运行此任务。该任务在没有异常的情况下运行,但对远程存储库没有影响。我对git很陌生,所以这可能是一个非常愚蠢的错误。RefSpec是否有问题?

如果在您上次获取或克隆后,在您尝试推送之前,其他人推送到同一分支,则会返回错误消息
拒绝非快进ref/heads/…

you> git clone ...

bob> git clone ...
bob> git commit
bob> git push

you> git commit
you> git push   <<-- error: denying non-fast-forward
you>git克隆。。。
bob>git克隆。。。
bob>git提交
鲍勃>吉特推
你可以提交

您>git push
PushCommand#call()
返回一个
PushResult
,该结果反过来保存一组
RemoteRefUpdate
s。你检查过这些吗?他们应该给你一个推送到底做了什么的线索。我收到一条信息:
错误:拒绝非快进引用/heads/mybranch(你应该先拉)
试图用谷歌搜索答案,但没有成功。也许我做错了什么,使用
git checkout--orphan mybranch
git rm--cached-r.
创建了新的空分支,然后向其中添加了一些文件?