JGit push does not update files

倖福魔咒の 提交于 2020-01-16 19:01:47

问题


I've been searching about this topic for a few days now and I can't get a solution. I've looked at this topic too: StackOverflow How to push JGit

The problem is I'm doing a program that should be a github with only the very basic functions, but when I do a push commit messages works fine but if I change the content of some files it does not update on the remote repository.

I use this for commit:

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

And I use this for pushing:

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

Anyone can help my with this?


回答1:


Have a look if the commits you are creating are correct using git show COMMIT_ID.

If not, the problem is that you didn't include the files you wan to commit with CommitCommand. The following corresponds to git commit -a -m msg:

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

You can also use setOnly(path) to include only certain files or directories in the commit. Call it multiple times for more than one path.

Another option would be if you add the files to the index first to stage it for commit (then you don't have to specify any files in commit):

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


来源:https://stackoverflow.com/questions/16834151/jgit-push-does-not-update-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!