0

I need to correlate each commit with the branch it is in. The only thing I have found that does this so far is "git show-branch" ... but this has problems with "cannot handle more than 25 refs" if there are more than 25 branches. I inherited this repo, and can not prune branches until I have an idea what commits have been duplicated in other branches, so I can not reduce the number of branches below the current 30 for now. Is there any other way to get a listing of all of the commits that identifies which branch the commit belongs to (e.g. some argument for git log --format)?

rimiha
  • 57
  • 5
  • [This question](https://stackoverflow.com/q/1419623/23118) asks the same. – hlovdal Dec 15 '22 at 01:36
  • Someone suggested: git branch --contains {sha} This is kind of the inverse of what I want. I could make this work with a perl script I suppose. First get the list of all the commits with their sha, then process it through that comment. Although ... this shows all branches that a given SHA is in. That would be a result once a branch is merged, or if you create branch B off of branch A. – rimiha Dec 15 '22 at 01:59
  • My end result is to cross reference branches that were cherry picked. E.g. branch A still exists, but maybe three of the five commits were cherry picked over to master. When you CP a commit from one branch to another, that gives them a different SHA. The only way I have been able to track that is by the commit message. As long as people don't use stupid "fixed typo" commit messages, the longer messages tend to be something you can use to correlate CP'd commits. Since I have to use a perl script to do that anyway I suppose the extra step isn't that difficult. – rimiha Dec 15 '22 at 02:03
  • I have been using the output of "git show-branch" for that. It has lines like this: + +++ + + ++ + [rc.artel_conflict] fix merge where "rc.artel_conflict" is a branch name, and the + signs are a column match for the branches listed above, in an indented format. I was just hoping there was a way to get this on the output of git log. prefereably in a single line format. I have one that produces:
    ts=2021-07-29 14:18:34 +0000;sha=0a29cf5;lbl=;c={Add JPEG ancillary info}
    to make it easy for processing with perl. If branch names could be added to that, nicer.
    – rimiha Dec 15 '22 at 02:07
  • But I guess --contains could be used for this. It's just that there will be a LOT of git calls from my perl script to do this for every commit in the repo ... :-P – rimiha Dec 15 '22 at 02:10
  • (sorry about the lack of line breaks ... I will have to figure out how to use this mini-markdown ...) ... two spaces at the end of a line? well, _that's_ intuitive! ... and it doesn't even work! – rimiha Dec 15 '22 at 02:13
  • 4
    You can't use extensive formatting in comments. That's why we generally ask people to update the question if they are adding substantial new information. – larsks Dec 15 '22 at 02:22
  • 2
    This definitely isn't a dup after reading the comments. (At least not a dup of the currently linked question. It might be closer to a dup of [this question](https://stackoverflow.com/q/2922652/184546).) I'd recommend putting your comments into the question as it's not clear in the original version of the question that you were referring to cherry-picked versions of the commits. Then it can possibly be re-opened, or matched to a better duplicate. – TTT Dec 15 '22 at 04:48
  • TBH in the original post I wasn't referring to the CP commits -- just the branches that the given commit belongs to. The same commit in multiple branches is usually just a result of branching. And "git show-branches" does have this information ... if you don't have more than 25 branches in the repo. I was pretty certain there isn't really a way to track cherry-picks, which is why I was writing a script using commit message matching. But ... I suppose if I had mentioned this in the first post, it might have been useful information. I just wanted to replace the show-branch info. – rimiha Dec 16 '22 at 19:01
  • I will try to edit the main (with formatting) later today. – rimiha Dec 16 '22 at 19:01

0 Answers0