私は git の新しいユーザーであり、JGitを使用してリモートの git リポジトリとやり取りしています。JGit では、CloneCommand
最初はレポのクローンを作成していましたが、問題なく動作しました。ただし、PullCommand
SVN update AFAIK に相当する を使用しようとすると、ローカル リポジトリの内容が更新されません。
これは私が使用したコードです:
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();
}
これは、コマンド ラインを使用してリモート リポジトリにプッシュした新しいファイルのローカル リポジトリを更新しません。ただし、ローカル リポジトリを削除して再度クローンを作成すると、すべての変更が反映されます。
PullCommand
JGitで使用する正しいアプローチを教えてください。
編集:
リモートリポジトリの構造:
root ____ file_1
|______ directory_1
|__________ file_2
|__________ file_3
directory_1 と 2 つのファイルは、最初のクローン作成後にコマンドラインからプッシュされます。ローカル リポジトリに反映されるように、このコードを試しましたが、これは発生していません。
リポジトリのクローンに使用されるコード:
File file = new File(localPath);
CloneCommand cloneCmd = git.cloneRepository();
try {
cloneCmd.setURI(remotePath)
.setDirectory(file)
.call();
} catch (GitAPIException e) {
e.printStackTrace();
}
ここでgit
、localPath
、remotePath
は上記と同じ変数です。