到目前为止我所做的是 -
尝试将更改推送到远程回购 //它显示消息为空且状态为OK但文件未被推送到远程回购。
另一个问题是,当我尝试打印推送消息时,它无限打印 - 消息 - 状态 - 确定 - 参考/头部/主人
private static final String REMOTE_URL = "http://abc.def.net/git/scm/nt/myprojectname.git"
String srcPath = "D://MyFiles//fol//ErrorFile.txt";
// prepare a new folder for the cloned repository
File localPath = File.createTempFile("TestGitRepository", "");
localPath.delete();
// then clone
System.out.println("Cloning from " + REMOTE_URL + " to " + localPath);
CredentialsProvider cp = new UsernamePasswordCredentialsProvider("myUserName","mypassword");
Git git = Git.cloneRepository().setURI(REMOTE_URL).setDirectory(localPath).setCredentialsProvider(cp).call();
String head = git.getRepository().getFullBranch();
if (head.startsWith("refs/heads/")) {
// Print branch name with "refs/heads/" stripped.
System.out.println("Current branch is " + git.getRepository().getBranch());
}
String destPath = localPath+"\\myprojectName\\" ;
File srcFile = new File(srcPath);
File destFile = new File(destPath);
FileUtils.copyFileToDirectory(srcFile, destFile, true) ;
git.checkout(); // MISSED THIS LINE EARLIER
// run the add-call
git.add().setUpdate(true).addFilepattern(destFile.getAbsolutePath()).call();
RevCommit revCommit = git.commit().setMessage("My First Commit").call();
System.out.println(revCommit.getShortMessage() );
Iterable<PushResult> resultIterable = git.push().setCredentialsProvider(cp).call();
while(resultIterable.iterator().hasNext()){ // LEADING TO INFINITE LOOP
PushResult result = resultIterable.iterator().next();
Collection<RemoteRefUpdate> rs = result.getRemoteUpdates();
for(RemoteRefUpdate rf : rs){
System.out.println("Msg- "+rf.getMessage() + " - Status - "+rf.getStatus() + " - "+rf.getSrcRef());
}
}
try {
System.out.println("Having repository: " + git.getRepository().getDirectory());
} finally {
git.getRepository().close();
}
答案 0 :(得分:0)
您的文件未提交,因为您需要指定要提交的文件。在你的情况下
git.commit().setAll(true)
应该可以工作,相当于git commit -a
我也有这个工作 -
CommitCommand commit = git.commit();
for (String file : files) {
commit.setOnly(file);
}
commit.setMessage(message).call()