【问题标题】:How to do a "git bundle create --all" in JGit?如何在 JGit 中执行“git bundle create --all”?
【发布时间】:2020-12-13 00:22:39
【问题描述】:

是否可以使用 JGit 捆绑存储库?

我正在尝试执行与此 git 命令等效的操作:

git --git-dir=path/to/my/local/repo bundle create path/to/backup.bundle --all

【问题讨论】:

    标签: git jgit git-bundle


    【解决方案1】:

    看着documentation,我会说yes

    public class BundleWriter
    extends Object
    

    创建一个 Git 捆绑文件,用于将运动鞋网传输到另一个系统。

    这是一个(未经测试的)示例:

    Repository repo = new FileRepositoryBuilder()
        .setGitDir(new File("path/to/my/local/repo/.git"))
        .build();
    BundleWriter bundle = new BundleWriter(repo);
    
    for (Ref ref : repo.getRefDatabase().getRefs()) {
        bundle.include(ref);
    }
    
    bundle.writeBundle(
        new NullProgressMonitor(),
        new FileOutputStream("path/to/backup.bundle"));
    

    【讨论】:

    • 对我来说就像一个魅力,谢谢。我遇到的唯一问题是 NullProgressMonitor() 不适用于我的特定 API 版本(5.8.1.202007141445-r)。我改用new EmptyProgressMonitor() {}
    猜你喜欢
    • 2016-12-04
    • 2015-07-02
    • 2012-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-17
    相关资源
    最近更新 更多