这可能是重复的,但我没有看到任何解决方案或正确的文档或示例。我正在尝试将 Git Hub 存储库下载到我的本地计算机。以下是我尝试过的。我正在使用 org.kohsuke.github API。我没有看到任何正确的方法来下载到本地。
public void cloneRep() {
String login = "userid";
String password = "password";
String rep = "repository";
String localDir = "/home/myuser/repository/";
try {
System.out.println("Connecting...." + login + " : " + password);
GitHub gitHub = GitHub.connectUsingPassword(login, password);
boolean isValid = gitHub.isCredentialValid();
System.out.println("is Valid ? " + isValid);
if (isValid) {
GHRepository repository = gitHub.getRepository(rep);
//how to clone the repository to local directory?
}
} catch (Exception e) {
System.out.println("EXCEPTION....");
e.printStackTrace();
}
}
我知道使用org.eclipse.jgit.api.Git这是可能的。
String remoteUrl = new StringBuffer().append("https").append(login)
.append(":").append(password).append("@github.com/")
.append(login).append("/").append(rep).toString();
org.eclipse.jgit.api.Git.cloneRepository().setURI(remoteUrl).setDirectory(localDir)
.call();
但这似乎更复杂。首先我只需要进行身份验证。然后我需要下载到本地。我没兴趣同时使用两者。如果 API 提供了更好的解决方案,我可以使用它。
有什么解决办法吗?
最佳答案
我可能是错的,但是 org.kohsuke.github API 是关于操作 github 上的存储库和 Gist 的。它与本地克隆存储库或执行其他 git 相关 Activity 无关。
关于Java GitHub API -org.kohsuke.github 将存储库克隆到本地计算机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30892451/