2

It is very common on our project to end up with these somewhat old branches that we want to resurrect but we're not sure what shared branch they were branched from.

So to try and put the question in as concrete terms as possible:

  1. I can identify a small set of "shared branches"
  2. I have a specific feature branch F

Is there a nice tool (preferably a GUI) that easily allows me to identify what shared branch F was branched from?

Mikhail
  • 20,685
  • 7
  • 70
  • 146
DaBlick
  • 898
  • 9
  • 21
  • Branches do not actually have parent branches. The information is not available and cannot be computed in general (though in many specific cases there's one obvious candidate). See also [Find the parent branch of a Git branch](https://stackoverflow.com/q/3161204/1256452). – torek Nov 28 '18 at 17:56
  • What does *cut from* mean, in this regard? The branch-point? – berkes Nov 29 '18 at 14:16
  • @torek The branch I was on when I created a new branch. – DaBlick Nov 30 '18 at 01:13
  • DaBlick: I think you meant to address that to @berkes. Anyway, Git doesn't formally save that information anywhere. The reflogs do have enough information to piece it together, for a while, until the reflog entries that have that information expire, but even that's just guessing, because you can run `git branch foo a123456` which makes new branch `foo` point to commit `a123456` regardless of your current commit / branch. – torek Nov 30 '18 at 01:44
  • Could you share more about your layout? E.g. do you shared branches have common parents, or they are like completely independent? If they share common parent (which is usually the case), are they merged to one another at some point or were they just branched off at some point to never meet again? – Mikhail Nov 30 '18 at 06:55
  • Do you know how to do this with git command line, and just asking about a UI tool? – Mikhail Nov 30 '18 at 06:59
  • @DaBlick I'm confused. You mean you want to know the [starting point](https://git-scm.com/docs/git-branch#git-branch-ltstart-point) of a branch? Because that is what `git log --graph --oneline` will use and show. This defaults to HEAD, meaning "the branch you are on right now". "What was checked out at moment of branching" is not registered in itself, though. – berkes Nov 30 '18 at 10:54
  • @berkes Yes, the starting point. I tried the git log command you suggested and it gave me an enormous output and it was not clear to me what the NAME of the branch I started the new branch from was. I am cognizant that this isn't an easy problem because, of course, I may branch from (say) release/3.0 but release/3.0 may have new commits added to it. And... other branches can be involved in various ways in the ancestor history. I guess what it boils down to is this. I want to know the name of the branch that has the most recent common ancestor. – DaBlick Nov 30 '18 at 13:08
  • @mikhail We have a sort of master branch, and we have release/X.Y branches. Feature branches are cut from either the master branch or a release/X.Y branch. Release branches can have common parents with master or with another release branch. So as I observed in my previous reply, the question really is one of "what is the most recent commit that is in any other branches." Then, from that set of other branches, eliminate all branches that that are derived from another branch in the set." – DaBlick Nov 30 '18 at 13:13
  • I'm inclined to mark this question duplicate of https://stackoverflow.com/questions/4477765/how-to-get-information-where-branch-starts Please let me know how your question differs from this question. – berkes Nov 30 '18 at 13:15
  • @berkes That's fine. – DaBlick Nov 30 '18 at 15:56
  • Possible duplicate of [How to get information where branch starts?](https://stackoverflow.com/questions/4477765/how-to-get-information-where-branch-starts) – berkes Dec 01 '18 at 17:17

1 Answers1

2

git log --graph --oneline <branchname> should show you the history of <branchname> and its branch-point.

berkes
  • 26,996
  • 27
  • 115
  • 206
  • Thanks, but I did not find it very easy to identify what branch this branch was cut from the output of that. I'm hoping there is something better. It is easy for me to determine the commit "before" my first commit. maybe another way to pose the question is how I determine what branches include that commit in their history? This actually is quite a bit closer to what I want: git for-each-ref --contains – DaBlick Nov 28 '18 at 17:00