0

I have a git repo that has multiple unmerged branches, and need to get a handle on what is where. SOME of them have had commits cherry-picked across, so if I do a list of commits using the top line of the log message, two of them would show the same text in different branches.

I have used git show-branch to show me all the commits and which branches they are in, and I can see some of them sharing the same text ... but I have to first pick a commit msg, then search (or grep) for that text to see if it appears in another branch.

Is there a way to automate this cross referencing of common commits across branches? So that I can get a list of all branches that the commit "this fixes the config problem" is in? Even better would be a list of cherry-picked commits and where their origin commit is, but I am not holding out hope for that. Just a list that shows that commit X appears in branches A, B, and C would be a tremendous help.

rimiha
  • 57
  • 5
  • "Is there a way to automate this cross referencing of common commits across branches? " Sure, with programming. For each branch (for each commit (record the branch name and commit subject)), and then index the result by the commit subject and see where you have multiple matches. – larsks Aug 24 '22 at 03:34

1 Answers1

0

git log has a set of options to detect cherry-picks : see --cherry-mark and below.

Sample usage :

git log --cherry master...my/branch
git log --cherry-mark master...my/branch

# with more options:
git log --graph --oneline --cherry master...my/branch
git log --graph --oneline --boundaries --cherry-mark master...my/branch

This will compare commits based on their content, so even if the message was edited a cherry-picked commit will be detected. A cherry-pick that led to a conflict will not be detected though (even if the messages are the same).

It will use the same algorithm as what git rebase uses to determine that a commit is already part of the target branch and shouldn't be replayed.

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • Thank you. I will have to look into that. ... related question: is there an easy way to determine which branches have been merged ... and if they were merged into something other to master, which branch was the target of the merge? – rimiha Aug 24 '22 at 07:19
  • If the branches are still there : `git branch --merged master` / `git branch --no-merged master`. For the second part of your question : I don't have an immediate answer, you can look at your commit graph and interpret from there. – LeGEC Aug 24 '22 at 08:17
  • @rimiha: Worth mentioning: `--cherry-mark` *requires* the use of the triple-dot `...` syntax. Branch names are not required: you can put in raw hash IDs for the two `rev`s. Git will use the symmetric difference code to find commits reachable on the left and right "sides", but not from "both sides", and with the `--cherry-mark` option, will mark patch-ID-equivalent commits in the resulting lists. – torek Aug 24 '22 at 18:54
  • Unfortunately ... the versions of git I have available do not have cherry-mark. (Sorry, I wrote this last night but apparently did not click the [add comment] button.) – rimiha Aug 25 '22 at 01:25
  • One way to "fix" this is to update git : are you using git on a machine where you can manage your software ? – LeGEC Aug 26 '22 at 06:46