我有一個開始提交,我想從中找到所有分支,直到達到另一個沒有找到提交提示。找到2個git提交之間可用的分支
commit 1
|
commit 2
| commit5
commit3/
| /
commit 4
|
commit 6
在這種情況下
說所有提交的提交1-5有筆記「中找到分支」 ,並承諾6沒有一個不與價值。
因此,我會從提交1開始,找到所有的父(即:提交2),並嘗試檢查是否有一個分支爲此提交(即:孩子的數量超過1)。如果有多於1名兒童的
- 的
getChildren()
方法有僅PlotCommit對象,但該方法parentCommit.getParents()
僅返回RevCommit
對象。 - 我想找到存在於特定的分支名提交
那麼當有對提交沒有更多的票據(即提交6可是沒有註釋)的邏輯將停在那裏和分行名稱的集合返回
Repository repo;//will be set as part of some other logic
private Set findBranchesForCommit(PlotCommit parentCommit, String note) throws ExecutionException, MissingObjectException, IncorrectObjectTypeException, IOException {
Set branches = new HashSet();
PlotCommit[] parents = (PlotCommit[]) parentCommit.getParents();//XXX will throw exception as this return RevCommit[]
for (int i = 0; i < parents .length; i++) {
PlotCommit commit = parents[i];
String result = extractExistingMessage(repo, "refs/notes", commit);//will return the if the note available for particular commit
if (result.trim().length() > 0 && result.equalsIgnoreCase(note)) {
System.out.println("#########"+commit.getChildCount());
//TODO need to add logic to find the branch of the particular commit
branches.add(""); //add the branches available for the commit
branches.addAll(findBranchesForCommit(commit, note));
}
}
return branches;
}
預期的結果
我想找到包含特定的git記提交的分支名稱。在上述例子中的分支名提交1和提交5將返回
我理解你的問題的問題。你只是在尋找'git branch --contains commit6'? – michas
總之。我想找到包含特定git note的提交的分支名稱。在上面的例子中,將返回Commit 1和Commit 5的分支名稱 –