【问题标题】:cannot git pull on a checked out branch in jgit无法在 jgit 中对已签出的分支进行 git pull
【发布时间】:2013-08-01 21:48:28
【问题描述】:

使用 jgit,我克隆了一个 git repo 的主分支,然后我用它检查了一个远程分支

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

然后我尝试在这个分支上 git pull,

git.pull().call()

但最终出现此错误

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)

我发现签出的分支在 .git/config 中没有更新,这可能是出现此错误消息的原因。那么该配置是否可以通过结帐以某种方式更新,或者 jgit 实际上是否允许 git pull 在签出的分支上?

(我知道我可以直接用jgit克隆一个分支,但我还是想找出上面的答案)

谢谢!

【问题讨论】:

  • 你能把.git/config的内容也包括在这里吗?

标签: git jgit


【解决方案1】:

尝试预先设置该配置:

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

【讨论】:

    猜你喜欢
    • 2018-08-06
    • 2012-04-26
    • 2020-06-10
    • 2019-01-10
    • 2015-09-26
    • 2012-05-25
    • 2021-05-15
    • 2020-02-18
    相关资源
    最近更新 更多