2013-05-30 45 views
0

我一直在尋找這個主題幾天了,我無法獲得解決方案。我也看過這個話題:StackOverflow How to push JGitJGit推送不會更新文件

問題是我正在做一個程序,應該是一個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(); 

任何人都可以幫我這個?

回答

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(); 
+0

謝謝robinst,問題是對提交缺少setAll()方法。 – Taka