简体   繁体   English

无法git在jgit中拉出已签出的分支

[英]cannot git pull on a checked out branch in jgit

With jgit, I cloned the master branch of a git repo, and I then I checked out a remote branch with this 使用jgit,我克隆了git repo的master分支,然后我用这个签出了一个远程分支

git.checkout()
.setCreateBranch(true)
.setName(branch)
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
.setStartPoint(s"origin/$branch")
.setForce(true)
.call()

I then tried to git pull on this branch, 然后我尝试在这个分支上进行git pull

git.pull().call() git.pull()()调用

but ended up with this error 但最终出现此错误

Exception in thread "main" org.eclipse.jgit.api.errors.InvalidConfigurationException: No value for key branch.X.Y.Z.merge found in configuration
at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:217)
at com.baml.cesium.sphinx.token.TestGIT$delayedInit$body.apply(TestGIT.scala:52)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:71)
at scala.App$$anonfun$main$1.apply(App.scala:71)
at scala.collection.immutable.List.foreach(List.scala:318)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
at scala.App$class.main(App.scala:71)
at com.baml.cesium.sphinx.token.TestGIT$.main(TestGIT.scala:15)
at com.baml.cesium.sphinx.token.TestGIT.main(TestGIT.scala)

I found out the checked out branch is not updated in .git/config, which is probably the reason for this error message. 我发现检出的分支未在.git / config中更新,这可能是此错误消息的原因。 So can that config be somehow updated with the checkout, or does jgit actually allow git pull on a checked out branch at all? 那么该配置是否可以通过检出以某种方式进行更新,或者jgit实际上是否允许git完全拉出检出分支?

(I know I can clone a branch directly with jgit, but I still want to find out the answer for the above) (我知道我可以直接使用jgit克隆分支,但我仍然想找出上述答案)

Thanks! 谢谢!

Try setting that configuration beforehand: 尝试预先设置该配置:

StoredConfig config = git.getRepository().getConfig();
config.setString("branch", "master", "merge", "refs/heads/master");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM