0

I have a long running git branch. I am trying to determine its ancestor. For example, if I am on a staging branch that split from master, the following commands would be perfect:

> git log --show-ancestor-branch
master

or

> git log --show-branches-with-common-ancestors
master

What I mean by ancestor is that master in the following log would be an ancestor of staging.

* 741c3fd (master) 
| * a8503ef (HEAD, staging) 
|/
| 
|
* bd783e3 Add simple query expressions

The following did not work:

*  `git log --ancestry-path`
* ` git merge-base -a`

The following would work in subversion:

svn log --stop-on-copy
Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467
  • possible duplicate of [Find the parent branch of a branch](http://stackoverflow.com/questions/3161204/find-the-parent-branch-of-a-branch) – isherwood Mar 04 '15 at 18:28

1 Answers1

1

I don't think that's possible to do, since in the end a branch is just a pointer to some commit hash, and it doesn't "leave marks" where it's been.

You could see who has the nearest common ancestor of your branch but that is not 100% guaranteed to be what you're looking for.

One thing we did on my team was, one the first commit in a new branch, write

Branched from some_branch

And we could track it like that. It's not very l33t but hey, it works :)

Shay Nehmad
  • 1,103
  • 1
  • 12
  • 25
  • Folks on my team would never agree to this. We like automation too much. I wish Git allowed an option to recognize parent branches by default. – Prachi Mar 30 '18 at 18:14