2

Let's say I have a git commit in the linux git repo, e.g. http://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/commit/?id=8c7188b23474cca017b3ef354c4a58456f68303a

How can I, starting from this commit, understand in which branches of the repo this commit is actually contained? A security provider tells me the above commit applies to the 2.6.x, 3.10.x, 3.12.x, 3.14.x, and the 3.4.x branches.

How are they able to determine this?

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
daniel f.
  • 1,421
  • 1
  • 13
  • 24
  • 4
    Possible duplicate of [How to list branches that contain a given commit?](http://stackoverflow.com/questions/1419623/how-to-list-branches-that-contain-a-given-commit) – Dan Lowe Jan 27 '16 at 14:37
  • Other possible duplicate- http://stackoverflow.com/questions/16304574/how-to-list-branches-that-contain-an-equivalent-commit – Andrew C Jan 27 '16 at 16:36
  • I do not believe that it is a duplicate. This goes beyond the simple usage of git, it is partially about the structure of the kernel repo itself. It becomes clear when you actually use the command explained in the "duplicate" answers. The above commit seems only to be contained in the master, however when browsing the release notes of kernel 4.3.3 you would see it is in there as well – daniel f. Jan 27 '16 at 16:59

1 Answers1

0

First, fetch to make sure you have the latest from your remote:

git fetch

Use the --contains option of the branch command:

git branch --all --contains 8c7188b23474cca017b3ef354c4a58456f68303a

--contains [] Only list branches which contain the specified commit (HEAD if not specified)

Jonathan.Brink
  • 23,757
  • 20
  • 73
  • 115
  • This does not work however. Your command only returns that that commit is in the master. However, looking at the release notes for the kernel 4.3.3 you can see that the commit above was included. – daniel f. Jan 27 '16 at 16:54
  • @danielf. This is probably because you don't have local copies of those other branches. Pass in the `--all` flag to see the results for all branches (local and remote) – Jonathan.Brink Jan 27 '16 at 17:10
  • I admit I am not a Git expert. I cloned the https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git repo locally. As far as i can see, it has many heads and quite a few tags. Am I missing something? – daniel f. Jan 27 '16 at 17:40
  • @danielf. In Git, when you clone a repo, you are cloning _everything_. So I would expect you to see quite a few branches and tags. Something that may be confusing is the concept of having local copies of all those branches though. After you clone you only have a local version of the master branch, but you have in fact downloaded every branch (there are edge-cases but not relevant to this discussion). To see the difference run the commands `git branch --local` and 'git branch --remote` – Jonathan.Brink Jan 27 '16 at 17:45
  • @danielf. To get your own copy of other branches use the "checkout" command, for example: `git checkout fooBranch` – Jonathan.Brink Jan 27 '16 at 17:46
  • so would i have to checkout each single branch, eg "origin/linux-4.3.y" and then search in there? Is there no way for me to check which (remote) branches contain the commit? – daniel f. Jan 27 '16 at 17:56
  • @danielf. No, to see if a branch (local or remote) has a particular commit you do not need to have it checked out. Use the `--all` flag as I have in my (updated) answer – Jonathan.Brink Jan 27 '16 at 17:59
  • Thank you for your patience. I think i had a fundamental error in my thought process. It seems as if a commit ported to another branch causes a new commit itself, meaning it has a different id. – daniel f. Jan 27 '16 at 18:06
  • @danielf. I see...one commit can be pointed to (_reachable_ would be a better term) by n number of branches. A branch is simply a pointer to a tree of commits – Jonathan.Brink Jan 27 '16 at 18:08
  • if i may abuse your patience one more time, I rephrased the question in a slightly better way here: http://stackoverflow.com/questions/35045071/git-command-to-find-backported-commits-in-linux-kernel-repo – daniel f. Jan 27 '16 at 18:19