org.eclipse.jgit.api.Git.reset()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(311)

本文整理了Java中org.eclipse.jgit.api.Git.reset()方法的一些代码示例,展示了Git.reset()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Git.reset()方法的具体详情如下:
包路径:org.eclipse.jgit.api.Git
类名称:Git
方法名:reset

Git.reset介绍

[英]Return a command object to execute a reset command
[中]返回命令对象以执行重置命令

代码示例

代码示例来源:origin: gocd/gocd

void cleanAndResetToMaster() throws IOException {
  try {
    git.reset().setMode(ResetCommand.ResetType.HARD).call();
    checkout("master");
    deleteBranch(BRANCH_AT_REVISION);
    deleteBranch(BRANCH_AT_HEAD);
  } catch (Exception e) {
    String currentBranch = git.getRepository().getBranch();
    LOGGER.error("Error while trying to clean up config repository, CurrentBranch: {} \n : \n Message: {} \n StackTrace: {}", currentBranch, e.getMessage(), e.getStackTrace(), e);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-config

private Ref resetHard(Git git, String label, String ref) {
  ResetCommand reset = git.reset();
  reset.setRef(ref);
  reset.setMode(ResetType.HARD);
  try {
    Ref resetRef = reset.call();
    if (resetRef != null) {
      this.logger.info(
          "Reset label " + label + " to version " + resetRef.getObjectId());
    }
    return resetRef;
  }
  catch (Exception ex) {
    String message = "Could not reset to remote for " + label + " (current ref="
        + ref + "), remote: " + git.getRepository().getConfig()
            .getString("remote", "origin", "url");
    warn(message, ex);
    return null;
  }
}

代码示例来源:origin: apache/incubator-gobblin

this.gitForPush.reset().setMode(ResetCommand.ResetType.HARD).setRef("HEAD~1").call();
this.gitForPush.push().setForce(true).setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.gitForPush.reset().setMode(ResetCommand.ResetType.HARD).setRef("HEAD~4").call();
this.gitForPush.push().setForce(true).setRemote("origin").setRefSpecs(this.masterRefSpec).call();

代码示例来源:origin: jphp-group/jphp

@Signature
public Memory reset(Environment env, ArrayMemory settings) throws GitAPIException {
  ResetCommand reset = getWrappedObject().reset();
  Memory mode = settings.valueOfIndex("mode");
  if (mode.isNotNull()) {
    reset.setMode(ResetCommand.ResetType.valueOf(mode.toString()));
  }
  Memory ref = settings.valueOfIndex("ref");
  if (ref.isNotNull()) {
    reset.setRef(ref.toString());
  }
  reset.disableRefLog(settings.valueOfIndex("disableRefLog").toBoolean());
  Memory paths = settings.valueOfIndex("paths");
  if (paths.isNotNull()) {
    ForeachIterator iterator = paths.getNewIterator(env);
    if (iterator != null) {
      while (iterator.next()) {
        reset.addPath(iterator.getValue().toString());
      }
    } else {
      reset.addPath(paths.toString());
    }
  }
  Ref call = reset.call();
  return GitUtils.valueOf(call);
}

代码示例来源:origin: apache/incubator-gobblin

.call();
this.git.reset().setMode(ResetCommand.ResetType.HARD).setRef(REMOTE_NAME + "/" + this.branchName).call();

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

private void resetSoftToParent() throws IOException,
    GitAPIException, CheckoutConflictException {
  Ref ref = repo.exactRef(Constants.ORIG_HEAD);
  ObjectId orig_head = ref == null ? null : ref.getObjectId();
  try (Git git = Git.wrap(repo)) {
    // we have already committed the cherry-picked commit.
    // what we need is to have changes introduced by this
    // commit to be on the index
    // resetting is a workaround
    git.reset().setMode(ResetType.SOFT)
        .setRef("HEAD~1").call(); //$NON-NLS-1$
  } finally {
    // set ORIG_HEAD back to where we started because soft
    // reset moved it
    repo.writeOrigHead(orig_head);
  }
}

代码示例来源:origin: openl-tablets/openl-tablets

private void reset() {
  try {
    git.reset().setMode(ResetCommand.ResetType.HARD).call();
  } catch (Exception e) {
    log.error(e.getMessage(), e);
  }
}

代码示例来源:origin: com.meltmedia.cadmium/cadmium-core

public void resetToRev(String revision) throws Exception {
 if(revision != null) {
  log.info("Resetting to sha {}", revision);
  git.reset().setMode(ResetType.HARD).setRef(revision).call();
 }
}

代码示例来源:origin: org.arquillian.smart.testing/git-rules

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
  throws IOException, ServletException {
  chain.doFilter(request, response);
  try {
    for (final LazilyLoadedRepository repository : repositories) {
      Git.wrap(repository.get()).reset().setMode(HARD).call();
    }
  } catch (GitAPIException e) {
    throw new ServletException(e);
  }
}

代码示例来源:origin: winstonli/writelatex-git-bridge

public void resetHard() throws IOException {
  Git git = new Git(getJGitRepository());
  try {
    git.reset().setMode(ResetCommand.ResetType.HARD).call();
  } catch (GitAPIException e) {
    throw new IOException(e);
  }
}

代码示例来源:origin: org.apereo.cas/cas-mgmt-support-version-control

/**
 * Reset.
 *
 * @param path the path
 * @throws GitAPIException the exception
 */
public void reset(final String path) throws GitAPIException {
  if (!isUndefined()) {
    git.reset().addPath(path).call();
  }
}

代码示例来源:origin: org.apereo.cas/cas-mgmt-support-version-control

private void resolveConflict(final String path) {
  try {
    git.reset().addPath(path).call();
    git.checkout().addPath(path).call();
  } catch (final Exception e) {
    LOGGER.error(e.getMessage(), e);
  }
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-contract-stub-runner

void reset(File project) {
  try (Git git = this.gitFactory.open(file(project))) {
    git.reset().setMode(ResetCommand.ResetType.HARD).call();
  }
  catch (Exception e) {
    throw new IllegalStateException(e);
  }
}

代码示例来源:origin: org.jboss.forge.addon/git-impl

@Override
public void resetHard(final Git repo, String newBase) throws GitAPIException
{
 repo.reset().setMode(ResetCommand.ResetType.HARD).setRef(newBase).call();
}

代码示例来源:origin: eclipse/winery

public void cleanAndResetHard() throws NoWorkTreeException, GitAPIException {
  // enable updating by resetting the content of the repository
  this.clean();
  // reset to the latest version
  ResetCommand reset = this.git.reset();
  reset.setMode(ResetType.HARD);
  reset.call();
}

代码示例来源:origin: org.openmrs.maven.plugins/openmrs-sdk-maven-plugin

/**
 * @inheritDoc
 */
@Override
public void resetHard(Git git, RevCommit commit){
  try {
    git.reset().setMode(ResetCommand.ResetType.HARD).setRef(commit.getName()).call();
  } catch (GitAPIException e) {
    throw new RuntimeException("Failed to hard reset to commit "+commit.getShortMessage(), e);
  }
}

代码示例来源:origin: org.wildfly.core/wildfly-server

/**
 * Reset hard on HEAD.
 *
 * @throws GitAPIException
 */
public void rollback() throws GitAPIException {
  try (Git git = getGit()) {
    git.reset().setMode(ResetCommand.ResetType.HARD).setRef(HEAD).call();
  }
}

代码示例来源:origin: wildfly/wildfly-core

/**
 * Reset hard on HEAD.
 *
 * @throws GitAPIException
 */
public void rollback() throws GitAPIException {
  try (Git git = getGit()) {
    git.reset().setMode(ResetCommand.ResetType.HARD).setRef(HEAD).call();
  }
}

代码示例来源:origin: org.wildfly.core/wildfly-server

@Override
public void rollback() {
  super.rollback();
  try (Git git = repository.getGit()) {
    git.reset().setMode(ResetCommand.ResetType.HARD).setRef(Constants.HEAD).call();
  } catch (GitAPIException ex) {
    MGMT_OP_LOGGER.failedToStoreConfiguration(ex, file.getName());
  }
}

代码示例来源:origin: danielflower/app-runner

private void gitUpdateFromOrigin() throws GitAPIException {
  git.fetch().setRemote("origin").call();
  git.reset().setMode(ResetCommand.ResetType.HARD).setRef("origin/master").call();
  this.contributors = getContributorsFromRepo();
}

相关文章