2

I’m trying to use the git history to find out when branches in a repository were created. I’m approximating a branch’s creation date as the date of the first commit on a branch. The repositories I’m dealing with have no activity in the list 90 days, so the Github API doesn’t store this information.

My current approach is :

  1. Use git log --merges to get all merge commits
  2. For each merge commit with parents A and B, use git merge-base A B to find the most recent common ancestor between those 2 commits. This is commit C.
  3. Use git log B..C to list all commits on the branch, and use the last commit’s commit date as an approximation date for when the branch was created.

I wanted to see if anyone knew of a more concise way to do this besides my approach above.

Thanks!

choconuvo
  • 21
  • 1
  • 1
    If the branches are linear (without merges between them) and you haven't done rebase, you are about as as you can get. But if you have merges between them or you have rebased, it won't work. – eftshift0 May 22 '20 at 23:31
  • 2
    Branches don't have creation dates, because branches—in the sense you mean, that is—simply don't *exist*. Commits exist; you can pick any set of commits and find their dates; but the set of commits you pick is a branch, and then when you're done with the set, that branch doesn't exist until you pick a set of commits again. Pick the *same* set, or a sufficiently similar set, and most people will agree that that's the same branch. Pick a different set, even if it includes the same commits, and people may or may not call it the same branch. – torek May 22 '20 at 23:32
  • 1
    Fundamentally, this means that the word *branch* has no agreed-upon meaning: Different reasonable attempts to define it produce different results. Other version control systems do have strong, persistent notions of branches: e.g., in Mercurial, you make a commit on some branch B and from then on, no matter how you find that commit, it's still on branch B. – torek May 22 '20 at 23:34
  • 1
    Git simply lacks this property. Any given commit *C* is "on" the branches whose branch names identify a commit that is a descendant of *C*. The set of names change over time. – torek May 22 '20 at 23:35
  • 2
    Locally I notice that if the reflog says "checkout: moving from develop to", it's likely to be the moment I created a branch name (because I check it out when I create it). That probably won't do you much good on github though. – matt May 22 '20 at 23:36
  • For more exploration of this same idea, see [the velociraptor answer](https://stackoverflow.com/a/3162929/1256452) :-) – torek May 22 '20 at 23:36

0 Answers0