JGit:每个命令的git子模块

问题描述 投票:3回答:1

我知道在JGit中对git子模块的支持是有限的,但仍然想知道如何实现这一点:

git submodule foreach git checkout <branchName>

以及使用JGit的类似命令。

或者还有其他更好的基于Java的Git API吗?

git git-submodules jgit
1个回答
4
投票

在JGit中,有一个SubmoduleWalk可能有助于解决您的问题。要在所有子模块上运行checkout命令,您可以按照以下方式编写:

try (SubmoduleWalk walk = SubmoduleWalk.forIndex(repository)) {
  while(walk.next()) {
    try (Repository submoduleRepository = walk.getRepository()) {
      Git.wrap(submoduleRepository).checkout().call();
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.