如何很难从一个混帐分支重置到其他的JGit? [英] How to hard reset from one git branch to other in JGit?

查看:218
本文介绍了如何很难从一个混帐分支重置到其他的JGit?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个分支一个是主,另一个1级。现在1级是我需要硬复位主人通常混帐bash的1级我可以做到这一点通过下面的命令。

I have two branches one is master and another one level1. Now level1 is the latest I need to hard reset master to level1 normally in git bash I can do that by following command.

$ git checkout master
$ git tag old-master-branch 
$ git reset --hard level1
$ git merge -s ours origin/master 
$ git push origin master

对于我来说这一次正常工作。我的问题是如何利用JGit实现它。我已经尝试过了。但我无法弄清楚如何设置源和目标分支。

This one works fine for me. My question is how can I achieve it by using JGit. I have tried it. But I am not able to figure out how to set the source and target branch.

考虑一个场景我已经克隆出了一个主分支

consider a scenario I have cloned a master branch

 Git git = Git.cloneRepository().setURI(remote).setCredentialsProvider(new UsernamePasswordCredentialsProvider("obuli", "xxxxxx")).setDirectory(gitPath)                    .setNoCheckout(true).call();

现在我需要硬重置为1级。

Now I need to hard reset it to the level1.

git.reset().setMode(ResetType.HARD).call();

不过,我在这里不指定1级。我不知道如何来指定。也请说如何提供 git的合并-s我们的产地/主在JGit

推荐答案

默认情况下, reset命令复位到头上。要重置到另一个分支,你需要指定这个分支 setRef()

By default the ResetCommand resets to HEAD. To reset to another branch, you need to specify this branch with setRef().

例如:

git.reset().setMode( ResetType.HARD ).setRef( "refs/heads/level1" ).call();

上面的指令会令当前分支点的最新提交的 1级的和检验其状态投入到工作目录。

The above command will let the current branch point to the latest commit of level1 and checkout its state into the work directory .

这篇关于如何很难从一个混帐分支重置到其他的JGit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆