我不知道如何删除远程分支。
以下代码及其与空源代码的变体:
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提前感谢您的想法和解决方案。
发布于 2012-09-12 17:35:33
这应该会对你有所帮助:
//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
发布于 2012-08-10 13:16:43
按照常规的git语法,你的RefSpec()不应该是::branchToDelete吗
发布于 2012-08-10 15:16:09
我从来没有这样做过,但是您只是通过指定origin/branchToDelete来尝试DeleteBranchCommand吗?
编辑:我特别指的是Git/JGit通过结构<remote name>/<branch name>引用远程分支(使用ListBranchCommand可以帮助你确保拼写正确)。
要了解分支名称的确切拼写,可以使用ListBranchCommand (不要忘记调用setListMode(REMOTE))。
注意: Git允许比JGit更奇怪的行为,所以除非它是在某个地方写的,否则不要期待它们。
编辑:我的意思是,refspec应该有以下语法:<remote branch>:<local branch> (或者可能相反),但是如果你错过了一端,就不要指望它在JGit中工作,即使它在Git中工作。
https://stackoverflow.com/questions/11892766
复制相似问题