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