2014-04-08 8 views
3

RebaseCommand, MergeCommand 또는 JGit의 다른 명령을 사용하여 커밋을 스쿼시하는 방법에 대한 제안 사항이 있습니까? 많은 예제를 찾을 수 없으며 문서가별로 도움이되지 않습니다.JGit : 커밋을 스쿼시하는 방법

간단한 예를 나는 다음과 같은 트리 스쿼시 할

이 하나에

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

을 :

Z가 숙청이 B, C의 커밋이다
A----Z-----H 

, D, E, FG.

모든 유용한 제안 및 유용한 자료를 제공해드립니다. 이것은 픽스와 C, D, E, F 및 G를 커밋 "픽스"를 선택한 후 git rebase -i ...를 사용하여 수행 될 명령 행 힘내에서

답변

5

는, Z는

B. 같은 커밋 메시지 것

JGit에서는 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(); 
+0

감사합니다. Google이나 SO를 통해 JGit을 사용하는 많은 예제를 찾을 수는 없지만 이클립스 버그/패치 보고서가 또 다른 좋은 정보원이라는 것을 알게되었습니다. https://git.eclipse.org/r/#/c/7779/6 /org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java – modulitos

+0

다음은 헤드 커밋을 포함하지 않은 커밋을 스쿼시하는 방법에 대한 또 다른 게시물입니다. http://stackoverflow.com/questions/ 26029698/git-squashing-continuous-commits-that-latest-recent-commits-and-do – modulitos

+0

샘플 누락에 관해서 : jgit-cookbook (https : // github)에 유용한 스 니펫을 수집하려고합니다. .com/centic9/jgit-cookbook / – centic