1

Is there a way to find all the commits in a repository that have a given parent?

I know many commits can have many parents. I want to find all commits that have a given parent. Since git write-tree lets you specify parents when creating a commit, and the parents are then stored in the commit (git cat-file -p lets you seem them quite plainly), I'd think that such a utility could brute force its way through the object store, test each object to see whether it is a commit, and if it is a commit, test whether any of its parents are the given commit.

In my case, I'm not even looking for performance—just results. And my repo is small.

The only similar question I've found is How to find all commits having a particular parent? That question is related to a Java library, and makes this seem way difficult. Is it?

Community
  • 1
  • 1
Dmitry Minkovsky
  • 36,185
  • 26
  • 116
  • 160
  • May I ask why you're trying to do this? –  Sep 06 '13 at 03:25
  • `reset --hard` and lost some commits that are now branch-less. I want to walk back through history going forward. Working with the reflog now, which is very helpful, of course, but would like my above-described approach as well. – Dmitry Minkovsky Sep 06 '13 at 03:28
  • 1
    What is the problem that you're trying to solve? Are you just trying to recover your lost commits? The reflog should have a record of which commit you were on before you did the hard reset, and using `git fsck` will show you all dangling commits. –  Sep 06 '13 at 03:45
  • Never ran `git fsck`—pretty sweet command there. Wish I had ran it before when I was confused. I seem to have git it worked out with just the reflog. – Dmitry Minkovsky Sep 06 '13 at 03:53
  • 1
    I would probably use `pygit2` for this. – Alex Chamberlain Sep 06 '13 at 07:45
  • Oh, was not aware of pygit(2). Thank you! – Dmitry Minkovsky Sep 06 '13 at 20:15

0 Answers0