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 7928797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:51:04+00:00 2026-06-03T19:51:04+00:00

How may I find all commits in a repository that have a specific parent?

  • 0

How may I find all commits in a repository that have a specific parent?

For example, if I have a commit A, I would like to find all other commits that share the parent with A. What would be the most effective, i.e. performant yet correct way to do this in LibGit2Sharp?

  • 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-03T19:51:05+00:00Added an answer on June 3, 2026 at 7:51 pm

    That’s a tricky question 😉

    The Git object allows to retrieve the parents of a commit. However, there’s no easy way to find the children of a commit.

    The following code would however partially solve this. The idea is to perform a git log from all the references of the repository (heads, tags, …) and, along the way, select every commit which bear a parent with the requested SHA.

    As the walk is being done from the most recent commits down the ancestor path, it may take some time, if you’re searching for the children of a very early commit in a repository with a very large history and many branches.

    [Fact]
    public void CanRetrieveChildrenOfASpecificCommit()
    {
        TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoPath);
        using (var repo = new Repository(path.RepositoryPath))
        {
            const string parentSha = "5b5b025afb0b4c913b4c338a42934a3863bf3644";
    
            var filter = new Filter
                             {
                                 /* Revwalk from all the refs (git log --all) ... */
                                 Since = repo.Refs, 
    
                                 /* ... and stop when the parent is reached */
                                 Until = parentSha
                             };
    
            var commits = repo.Commits.QueryBy(filter);
    
            var children = from c in commits
                        from p in c.Parents
                        let pId = p.Id
                        where pId.Sha == parentSha
                        select c;
    
            var expectedChildren = new[] { "c47800c7266a2be04c571c04d5a6614691ea99bd", 
                                            "4a202b346bb0fb0db7eff3cffeb3c70babbd2045" };
    
            Assert.Equal(expectedChildren, children.Select(c => c.Id.Sha));
        }
    }
    

    Limits:

    • This will not retrieve commits that have been rewritten (through amend or rebase, for instance) as LibGit2Sharp doesn’t expose a way to access the reflog (yet)
    • Unreachable (dangling) commits won’t either be retrieved with this proposal.

    Test repository:

    The content of the repository being queried is show below

    $ git log --all --graph
    * commit 4c062a6361ae6959e06292c1fa5e2822d9c96345
    | Author: gor <gorbach.alexey@gmail.com>
    | Date:   Thu Apr 14 18:44:16 2011 +0300
    |
    |     directory was added
    |
    *   commit be3563ae3f795b2b4353bcce3a527ad0a4f7f644
    |\  Merge: 9fd738e c47800c
    | | Author: Scott Chacon <schacon@gmail.com>
    | | Date:   Tue May 25 11:58:27 2010 -0700
    | |
    | |     Merge branch 'br2'
    | |
    | | * commit e90810b8df3e80c413d903f631643c716887138d
    | | | Author: Vicent Marti <tanoku@gmail.com>
    | | | Date:   Thu Aug 5 18:42:20 2010 +0200
    | | |
    | | |     Test commit 2
    | | |
    | | * commit 6dcf9bf7541ee10456529833502442f385010c3d
    | |   Author: Vicent Marti <tanoku@gmail.com>
    | |   Date:   Thu Aug 5 18:41:33 2010 +0200
    | |
    | |       Test commit 1
    | |
    | | *   commit a4a7dce85cf63874e984719f4fdd239f5145052f
    | | |\  Merge: c47800c 9fd738e
    | |/ /  Author: Scott Chacon <schacon@gmail.com>
    | | /   Date:   Tue May 25 12:00:23 2010 -0700
    | |/
    |/|         Merge branch 'master' into br2
    | |
    * | commit 9fd738e8f7967c078dceed8190330fc8648ee56a
    | | Author: Scott Chacon <schacon@gmail.com>
    | | Date:   Mon May 24 10:19:19 2010 -0700
    | |
    | |     a fourth commit
    | |
    * | commit 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
    | | Author: Scott Chacon <schacon@gmail.com>
    | | Date:   Mon May 24 10:19:04 2010 -0700
    | |
    | |     a third commit
    | |
    | * commit c47800c7266a2be04c571c04d5a6614691ea99bd
    |/  Author: Scott Chacon <schacon@gmail.com>
    |   Date:   Tue May 25 11:58:14 2010 -0700
    |
    |       branch commit one
    |
    * commit 5b5b025afb0b4c913b4c338a42934a3863bf3644
    | Author: Scott Chacon <schacon@gmail.com>
    | Date:   Tue May 11 13:38:42 2010 -0700
    |
    |     another commit
    |
    * commit 8496071c1b46c854b31185ea97743be6a8774479
      Author: Scott Chacon <schacon@gmail.com>
      Date:   Sat May 8 16:13:06 2010 -0700
    
          testing
    
    * commit 41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9
    | Author: Scott Chacon <schacon@gmail.com>
    | Date:   Tue May 11 13:40:41 2010 -0700
    |
    |     packed commit two
    |
    * commit 5001298e0c09ad9c34e4249bc5801c75e9754fa5
      Author: Scott Chacon <schacon@gmail.com>
      Date:   Tue May 11 13:40:23 2010 -0700
    
          packed commit one
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text of 10000000 character in that I want to find all
That may be really simple but I'm unable to find a good answer. How
This may sounds like a stupid question but can't find anything on google, probably
Im trying to find records in a VARCHAR column that may contain a NUL
I have this DB diagram and want to make a query to find all
Let's say I want to find all sets of 5 single-digit, non-repeating numbers that
I have the following line in a view: <%= f.select(:province_id, options_from_collection_for_select(Province.find(:all, :conditions => {
I have an index view that lists all of the tags for my Entry
In my Jobs controller I have this statement under the index() function: $this->Job->find('all', array('conditions'
ok i have a file that may or may not be newlined or carriage

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.