JGit:如何压缩提交 [英] JGit: How to squash commits

查看:57
本文介绍了JGit:如何压缩提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于如何在JGit中使用 RebaseCommand MergeCommand 或任何其他命令来压缩提交的任何建议?我找不到很多示例,并且文档不是很有帮助.

Any suggestions on how to use RebaseCommand, MergeCommand or any other command in JGit to squash commits? I cannot find many examples and the documentation is not very helpful.

一个简单的示例

我要压扁以下树:

A-----B------C------D------E------F------G------H

进入这一个:

A----Z-----H

其中 Z B C D E F G .

感谢任何建议和有用的资源.

Any suggestions and useful resources are appreciated.

推荐答案

在命令行Git中,这将使用 git rebase -i ... 完成,然后选择"fixup"进行提交C,D,E,F和G.通过修正,Z将具有与B相同的提交消息.

In command-line Git, this would be done using git rebase -i ... and then selecting "fixup" for commits C, D, E, F and G. With fixup, Z would have the same commit message as B.

在JGit中,这可以使用RebaseCommand完成:

In JGit, this can be done using RebaseCommand:

InteractiveHandler handler = new InteractiveHandler() {
    public void prepareSteps(List<RebaseTodoLine> steps) {
        // loop through steps and use setAction to change action
    }

    public String modifyCommitMessage(String oldMessage) {
        return oldMessage;
    }
};

Repository repo = FileRepositoryBuilder.create(gitDir);
Git git = Git.wrap(repo);
git.rebase().setUpstream(commitA).runInteractively(handler).call();

这篇关于JGit:如何压缩提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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