相关疑难解决方法(0)

JGit:签出一个远程分支

我正在使用JGit来检查远程跟踪分支.

Git binrepository = cloneCmd.call()

CheckoutCommand checkoutCmd = binrepository.checkout();
checkoutCmd.setName( "origin/" + branchName);
checkoutCmd.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK );
checkoutCmd.setStartPoint( "origin/" + branchName );

Ref ref = checkoutCmd.call();
Run Code Online (Sandbox Code Playgroud)

文件已签出,但HEAD未指向分支.以下是git status输出,

$ git status
# Not currently on any branch.
nothing to commit (working directory clean)
Run Code Online (Sandbox Code Playgroud)

可以在git命令行中轻松执行相同的操作,它可以正常工作,

git checkout -t origin/mybranch
Run Code Online (Sandbox Code Playgroud)

怎么做这个JGit?

git jgit

21
推荐指数
2
解决办法
2万
查看次数

我如何使用JGit进行git推送?

我正在尝试构建一个允许用户使用基于Git的存储库的Java应用程序.我可以使用以下命令从命令行执行此操作:

git init
<create some files>
git add .
git commit
git remote add <remote repository name> <remote repository URI>
git push -u <remote repository name> master
Run Code Online (Sandbox Code Playgroud)

这允许我创建,添加和提交内容到我的本地存储库并将内容推送到远程存储库.我现在正试图在我的Java代码中使用JGit做同样的事情.我能够轻松地使用JGit API执行git init,添加和提交.

Repository localRepo = new FileRepository(localPath);
this.git = new Git(localRepo);        
localRepo.create();  
git.add().addFilePattern(".").call();
git.commit().setMessage("test message").call();
Run Code Online (Sandbox Code Playgroud)

同样,所有这一切都很好.我找不到任何例子或者等效代码git remote addgit push.我确实看过这个问题.

testPush()失败并显示错误消息TransportException: origin not found.在其他例子我见过https://gist.github.com/2487157git clone 之前 git push,我不明白为什么这是必要的.

任何有关如何做到这一点的指示将不胜感激.

git jgit

19
推荐指数
2
解决办法
2万
查看次数

标签 统计

git ×2

jgit ×2