JGit push不会更新文件

时间:2013-05-30 10:47:27

标签: java jgit

我几天来一直在搜索这个话题,我无法得到解决方案。 我也看过这个话题:StackOverflow How to push JGit

问题是我正在做一个应该是只有非常基本功能的github的程序,但是当我做推送提交消息工作正常但如果我改变某些文件的内容它不会在远程更新库中。

我用它来提交:

 Repository localRepo = new FileRepository(repository + "\\.git");
 Git git = new Git(localRepo);  
 git.commit().setCommitter(txtCommiter.getText(),"").setMessage(txtCommit.getText()).call();

我用它来推动:

Repository localRepo = new FileRepository(this.repository + "\\.git");
Git git = new Git(localRepo);
PushCommand push = git.push();
UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider(this.userName, this.pwd);
push.setCredentialsProvider(user);
push.setRemote(this.remote);
push.call();

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:3)

使用git show COMMIT_ID查看您创建的提交是否正确。

如果没有,问题是你没有包含你要用CommitCommand提交的文件。以下内容对应git commit -a -m msg

 git.commit().setAll(true).setMessage(msg).call();

您还可以使用setOnly(path)仅包含提交中的某些文件或目录。多次调用多个路径。

另一种选择是,如果您首先将文件添加到索引以将其暂存以进行提交(那么您不必在提交中指定任何文件):

git.add().addFilepattern(dirA).addFilepattern(fileB).call();