0
我所做的到现在是 -JGit - 将一个特定的文件RemoteRepo
- 从远程回购克隆。
- 添加文件到指定的目录在我的项目,并取得了该文件
- 文件提交
试图推动修改远程回购 一些变化//它显示我的消息在空和地位确定但该文件没有被推送到远程回购。
的另一个问题是,当我试图打印推送消息是无限印刷 - MSG-空 - 状态 - 确定 - 裁判/头/主
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();
}
检查gitignore。该文件或其祖先文件夹中的一个? – 2014-12-19 08:01:34
有了Git,你不会推送文件,你推送提交。你是如何确定刚刚创建的提交从未在目标git中结束的? – 2014-12-19 08:22:57
@MagnusBäck,你可以推送文件,也就是说你创建一个文件,添加它,提交并推送它。 – 2014-12-19 08:31:55