我理解Git fetch的概念。我想通过JGit应用程序接口中的FetchCommand类来获取对象。
我有一个Git存储库。例如C:\jGit\.git。
我已经克隆了这个存储库。例如:C:\jGitClone\jGit\.git。
我再次克隆了这个存储库。例如C:\Users\user\Desktop\jGitClone\.git。
使用Git,我有一个JGit类:
Git git = new Git(repository); // this is the cloned repository. C:\jGitClone\jGit\.git我该如何设置桌面上的克隆存储库,这样当fetch被调用时,它就知道要提取到这个存储库中。
我已经看了一些网站,包括下面的1,但仍然卡住了。
Git fetch failing using jgit: Remote does not have available for fetch
发布于 2012-09-17 19:36:42
我想你漏掉了什么。在Git/jGit中,本地副本由path (就像在文件系统中一样)和remote (远程存储库)确定。
在您的示例中,您希望桌面克隆存储库具有指向jGitClone/jGit存储库的链接。因此,首先,如果克隆已经完成,那么桌面存储库就知道它的远程存储库。因此,在您的代码中,您只需要告诉您的桌面代码库在哪里:
Builder builder = new FileRepositoryBuilder()
Git repo = builder.setGitDir(new File("C:\Users\user\Desktop\jGitClone.git"))
.readEnvironment()
.build()代码可能不能直接工作(我没有测试它,我的疑虑是在给出的路径上,以及要使用的对象:Builder、Git),但它基于以下答案,我认为它会对您有所帮助:JGit and finding the Head
顺便说一句,你的问题不是很清楚:你已经克隆了所有的东西,还是你想要做的?在您的代码中,您提到了一个repository:您是否使用类似于我建议的代码来获取它?您选择的名称也不是很清楚:除非包含jGit源代码,否则调用repo jGit听起来有点笨拙。另外,给你的不同的repos (A,B,C)命名,以便有更清晰的理解。
发布于 2020-09-15 12:09:56
您需要定义remote,它跟踪您可以从中获取提交的存储库,使用valina git,您可以这样做:
# suppose you have cloned C:\jGitClone\jGit\.git
$ cd C:\Users\user\Desktop\jGitClone\.git
$ git remote add upstream "C:\jGitClone\jGit\.git"
$ git fetch upstream如果你想尝试git24j,你可以用java来做,就像你用valina git做的那样:
Repository remote = Repository.open("C:\jGitClone\jGit\.git");
Repository local = Repository.open("C:\Users\user\Desktop\jGitClone\.git");
// set up remote
Remote upstream = Remote.create(local, "upstream", URI.create(remote.getPath()));
// fetch from remote
upstream.fetch(null, null, "reflog");两个nulls是定义要获取的refspecs和选项(您可以在其中设置凭证等)的参数。
https://stackoverflow.com/questions/12424825
复制相似问题