繁体   English   中英

Jgit - 从特定分支结帐

[英]Jgit - checkout from a specific branch

我正在使用 jgit。 我想创建并签出一个新分支。 我看过 git.checkout.createnewbranch 命令。 有没有办法指定结帐的基本分支,比如“测试”(或者)我们必须结帐,先拉“测试”,然后从中结帐/创建新分支?

是的,有可能:

Git git = Git.cloneRepository()
    .setURI("https://github.com/eclipse/jgit.git") // just an example uri
    .setDirectory("/path/to/repo")
    .setCloneAllBranches(true)
    .call();

git.checkout()
    .setCreateBranch(true)
    .setName("new-branch")
    .setStartPoint("<base branch>") // if it's a remote base then use origin/ prefix
    .call();

不要忘记调用git.close()或使用try-with-resources

暂无
暂无

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

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