gpt4 book ai didi

java - 如何使用 JGit 删除远程分支

转载 作者:太空狗 更新时间:2023-10-29 14:26:13 25 4
gpt4 key购买 nike

我不知道如何删除远程分支。

我试图模仿以下 GIT 命令: git 推送原点:分支删除

以下代码及其与空源的变体:

RefSpec refSpec = new RefSpec();
refSpec = refSpec.setSource("");
// remove branch from origin:
git.push().setRefSpecs(refSpec).add(branchToDelete).call();

抛出和异常如下:

org.eclipse.jgit.api.errors.JGitInternalException: Exception caught during execution of push command
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:175)
at org.gitscripts.DeleteBranchOperation.execute(DeleteBranchOperation.java:27)
at org.gitscripts.Main.main(Main.java:27)
Caused by: java.io.IOException: Source ref doesnt resolve to any object.
at org.eclipse.jgit.transport.RemoteRefUpdate.<init>(RemoteRefUpdate.java:285)
at org.eclipse.jgit.transport.RemoteRefUpdate.<init>(RemoteRefUpdate.java:189)
at org.eclipse.jgit.transport.Transport.findRemoteRefUpdatesFor(Transport.java:612)
at org.eclipse.jgit.transport.Transport.findRemoteRefUpdatesFor(Transport.java:1150)
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:149)
... 2 more

提前感谢您的想法和解决方案。

最佳答案

这应该可以帮助您:

//delete branch 'branchToDelete' locally
git.branchDelete().setBranchNames('refs/heads/branchToDelete').call();

//delete branch 'branchToDelete' on remote 'origin'
RefSpec refSpec = new RefSpec()
.setSource(null)
.setDestination("refs/heads/branchToDelete");
git.push().setRefSpecs(refSpec).setRemote("origin").call();

使用 jgit 2.0.0.201206130900-r 测试

关于java - 如何使用 JGit 删除远程分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11892766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com