Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9064955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:23:03+00:00 2026-06-16T16:23:03+00:00

I have a start commit from which i want to find all the branches

  • 0

I have a start commit from which i want to find all the branches till i reach another dont find a note for the commit.

commit 1
|
commit 2
|         commit5
commit3  /
|       / 
commit 4
|
commit 6

in this case say all the commit from commit 1-5 have notes “find branch”
and commit 6 doesn’t have a not with that value.

So i will start with commit 1 find all the parent (ie: commit 2) and try to check if there is an branch for this commit (ie: number of children is more than 1). if there is more than 1 childs

  1. the getChildren() method is there only for PlotCommit object, but the method parentCommit.getParents() return only RevCommit Object.
  2. i want to find the branch name present in the particular commit

then when there is no more notes on the commit (ie commit 6 doesnt have notes) the logic will stop there and the collection of Branch name is returned

    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;
    }

expected result

i want to find the branch names of commits that contain a particular git note. in the above example the branch name of Commit 1 and commit 5 will be returned

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:23:04+00:00Added an answer on June 16, 2026 at 4:23 pm

    While the git command for this kind of request (finding branches for a given commit) is:

    git branch --contains <commit>
    

    (as in “Git: Finding what branch a commit came from“, and “How to list branches that contain a given commit?“)

    it isn’t implemented as is in JGit.

    This thread has this to propose:

    ‘git branch --contains <commit>‘ will report every branch which contains this commit.
    In the standard push/fetch workflows for all commits you get from remote only “origin/master” is reported.
    And even for local commits: Imagine you have merged your feature branch back to master. Then this command will report also the master branch and all feature branches created after merging.
    Git simply doesn’t store for a revision on which branch it was created.

    After these warnings: a rough implementation of “git branch –contains ” could look like this:

    Repository repo = new FileRepository(args[0]);
    RevWalk walk = new RevWalk(repo);
    RevCommit commit = walk.parseCommit(repo.resolve(args[1] + "^0"));
    for (Map.Entry<String, Ref> e : repo.getAllRefs().entrySet())
      if (e.getKey().startsWith(Constants.R_HEADS))
        if (walk.isMergedInto(commit,
            walk.parseCommit(e.getValue().getObjectId())))
          System.out.println("Ref " + e.getValue().getName()
                                    + " contains commit " + commit);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have start date and end date. I need to find out the day
I have to start work on phone gap. Till now i have found out
I have a start and end time in a timestamp format. I want to
About to start a new project in VS2010 which will have a few windows
I have a shell script which I'd like to trigger from a J2EE web
I have a scenario in which from an activity, on the click of a
I have a method that transfers data from one database to another and in
I have subversion server with a post-commit hook to do something. I want the
I have a url which I want to save into the MySQL database using
I have start date and end date. I also have particular day i.e. wednesday.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.