【发布时间】:2012-11-04 04:45:57
【问题描述】:
我是 git 的新用户,正在使用 JGit 与远程 git 存储库进行交互。在 JGit 中,我最初使用 CloneCommand 来克隆一个 repo,它可以正常工作。但是,当我尝试使用 PullCommand(相当于 SVN 更新 AFAIK)时,本地 repo 内容不会更新。
这是我使用的代码:
private String localPath;
private Repository localRepo;
private Git git;
localPath = "/home/test/git_repo_test";
remotePath = "https://github.com/test/repo_1.git";
try {
localRepo = new FileRepository(localPath + "/.git");
} catch (IOException e) {
e.printStackTrace();
}
git = new Git(localRepo);
PullCommand pullCmd = git.pull();
try {
pullCmd.call();
} catch (GitAPIException e) {
e.printStackTrace();
}
这不会为我使用命令行推送到远程存储库的新文件更新本地存储库。但是,如果我删除本地存储库并再次进行克隆,则会反映所有更改。
请告诉我在 JGit 中使用PullCommand 的正确方法是什么。
编辑:
远程仓库的结构:
root ____ file_1
|______ directory_1
|__________ file_2
|__________ file_3
directory_1 和这两个文件是在初始克隆后从命令行推送的,我尝试了这段代码,以便它反映在本地存储库中,但没有发生。
用于克隆存储库的代码:
File file = new File(localPath);
CloneCommand cloneCmd = git.cloneRepository();
try {
cloneCmd.setURI(remotePath)
.setDirectory(file)
.call();
} catch (GitAPIException e) {
e.printStackTrace();
}
这里,git、localPath 和 remotePath 是与上面相同的变量。
【问题讨论】:
-
能否包含用于克隆存储库的代码?