2014-12-19 73 views
0

我所做的到现在是 -JGit - 将一个特定的文件RemoteRepo

  1. 从远程回购克隆。
  2. 添加文件到指定的目录在我的项目,并取得了该文件
  3. 文件提交
  4. 试图推动修改远程回购 一些变化//它显示我的消息在空和地位确定但该文件没有被推送到远程回购

    的另一个问题是,当我试图打印推送消息是无限印刷 - 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(); 
} 
+0

检查gitignore。该文件或其祖先文件夹中的一个? – 2014-12-19 08:01:34

+0

有了Git,你不会推送文件,你推送提交。你是如何确定刚刚创建的提交从未在目标git中结束的? – 2014-12-19 08:22:57

+0

@MagnusBäck,你可以推送文件,也就是说你创建一个文件,添加它,提交并推送它。 – 2014-12-19 08:31:55

回答

0

您的文件没有提交,因为你需要指定你想提交的文件。在你的情况

git.commit().setAll(true) 

应该工作,其相应的Git的承诺-a

我也得到了这个工作 -

CommitCommand commit = git.commit(); 
for (String file : files) { 
    commit.setOnly(file); 
} 
commit.setMessage(message).call() 
相关问题