3

I want to find tagged revisions that include a given merge. I found this question about finding commits in a tagged revision, which I fail to put it in practice.

Concrete case: finding tagged revisions of matplotlib that contains this merge.

I go to the list of commits included in the merge, I take the first one with id cf11aea and type

git tag --contains cf11aea

This does not return any result.

When trying to look at commits with the same patch id with the script given in the question above, it returns a single answer — the original commit.

So how to find tagged revisions with a given merge, is this different from finding tagged revisions with a given commit?

(This question is not about matplotlib itself.)

EDIT

One explanation could be indeed that the merge is not part of any tagged revision. However modifications brought by this merge can be seen in the source of tagged revisions. E.g. this modified line from cf11aea can been seen in the source of v2.0.0.

P-Gn
  • 23,115
  • 9
  • 87
  • 104
  • "This does not return any result". Well, what if that is correct? Are you sure that commit **is** part of a tag? If so, how do you know? Also, which tag(s) would that be? – Lasse V. Karlsen Jul 24 '17 at 11:05
  • @Lasse I edited my question to bring in some arguments. – P-Gn Jul 24 '17 at 11:24
  • Did you try `git tag --merged` ? – coredump Jul 24 '17 at 11:28
  • @coredump I don't quite understand the behavior of `--merge`. It returns tags like `v0.91.2` that are ten years old — this merge is from last year. Perhaps is it the reverse of what I am looking for? – P-Gn Jul 24 '17 at 11:44
  • It appears that particular commit was cherry-picked onto another branch, that's why the changes it introduces (merges in) are part of that other branch whereas the commit that originally introduced it isn't. See commits `659513951920d83fe6ef68ec40dd72f7bd6d6653` (not a merge) and `5b74696f838a43bcedc4bc568f0564f87f2fc71a` (merge) – Lasse V. Karlsen Jul 24 '17 at 11:45

2 Answers2

3

To answer your main question, how do you find all tags that contains a given commit?

Exactly as you tried:

git tag --contains COMMIT-ID

If the output of this command is empty, then no tag contains the specified commit.


So I would say you got the command right but the example or repository wrong.

Let's analyze.

You're looking for all tags that contain a specific commit, in your example you're looking for the commit cf11aea in all tags in matplotlib.

However, no tags in that repository contains that commit.

Here's why.

You cite a pull request, pull request #5718, and there are in fact two commits in that repository that reference this pull request:

commit 5b74696f838a43bcedc4bc568f0564f87f2fc71a
Merge: 18169b295 c9b2425fa
Author: Thomas A Caswell <tcaswell@gmail.com>
Date:   Wed Feb 17 21:35:50 2016 -0500

    Merge pull request #5718 from mdboom/image-interpolation

    Rewrite of image infrastructure

commit 659513951920d83fe6ef68ec40dd72f7bd6d6653
Author: Thomas A Caswell <tcaswell@gmail.com>
Date:   Wed Feb 17 21:35:50 2016 -0500

    Merge pull request #5718 from mdboom/image-interpolation

    Rewrite of image infrastructure
    Conflicts:
            lib/matplotlib/tests/test_axes.py
                - do not back-port appveyor spceific limits
            lib/matplotlib/tests/test_image.py
                - do not backport the jpeg_alpha test
            setupext.py
               - do not include windows/appveyor related changes

Take a look of the top 2-3 lines of each of those two:

commit 5b74696f838a43bcedc4bc568f0564f87f2fc71a
Merge: 18169b295 c9b2425fa
Author: Thomas A Caswell <tcaswell@gmail.com>

commit 659513951920d83fe6ef68ec40dd72f7bd6d6653
Author: Thomas A Caswell <tcaswell@gmail.com>

As you can see, the first one is a merge, the other one isn't. The other one is most likely a cherry-pick of the first one.

Let's see which tags contains these commits:

λ git tag --contains 5b74696f838a43bcedc4bc568f0564f87f2fc71a
λ git tag --contains 659513951920d83fe6ef68ec40dd72f7bd6d6653
v2.0.0
v2.0.0b1
v2.0.0b2
v2.0.0b3
v2.0.0b4
v2.0.0rc1
v2.0.0rc2
v2.0.1
v2.0.2

So the original merge, of the pull request, is not part of any tags whereas the cherry-picked commit is (on re-reading I'm assuming it is in fact a squash or something similar).

This is why the commit you're looking for, cf11aea, is not part of any tag.

In conclusion, your premise was wrong. You took the empty output of git tag --contains cf11aea as an indication that you had done something wrong, but you've used the right command, it was just the assumption that cf11aea was part of a tag that was wrong.


To answer your question in the comments, how did I find that other commit? Well, two ways but let's deal with the one that put me on the right track first:

I checked out the tag v2.0.0 and then executed:

git blame extern\agg24-svn\include\agg_span_image_filter_gray.h

Line 493 (+ surrounding lines) in this output looks like this:

121ee67b4d agg24/include/agg_span_image_filter_gray.h            (Michael Droettboom 2007-11-16 15:53:57 +0000 490)                     fg_ptr = (const value_type*)base_type::source().next_y();                                          
121ee67b4d agg24/include/agg_span_image_filter_gray.h            (Michael Droettboom 2007-11-16 15:53:57 +0000 491)                 }                                                                                                      
121ee67b4d agg24/include/agg_span_image_filter_gray.h            (Michael Droettboom 2007-11-16 15:53:57 +0000 492)                                                                                                                        

6595139519 extern/agg24-svn/include/agg_span_image_filter_gray.h (Thomas A Caswell   2016-02-17 21:35:50 -0500 493)                 fg = color_type::downshift(fg, image_filter_shift);                                                    

121ee67b4d agg24/include/agg_span_image_filter_gray.h            (Michael Droettboom 2007-11-16 15:53:57 +0000 494)                 if(fg < 0) fg = 0;                                                                                     
2a178393c0 extern/agg24/include/agg_span_image_filter_gray.h     (Michael Droettboom 2014-10-15 10:35:38 -0400 495)                 if(fg > color_type::full_value()) fg = color_type::full_value();                                       
121ee67b4d agg24/include/agg_span_image_filter_gray.h            (Michael Droettboom 2007-11-16 15:53:57 +0000 496)                 span->v = (value_type)fg;                                                                              

(I separated out line 493 from the rest for clarity)

The first part is the commit id that introduced the changes.

I then looked at that commit, and you can see the output above, and found that it wasn't a merge commit. Clearly this was not the merge for that pull request.

At this point I did this:

git log --graph >c:\log.txt

Opened it up in Notepad++ and used the "Find" function to find 5718, and found two commits, and the rest is history.

Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
1

In addition to what Lasse wrote in his answer, here’s a GitHub-only solution to get to the same result:

What you should be looking for on the pull request is the information about the pull request resolution. In this case, it looks like this:

Pull request resolution: Merge commit

So here, tacaswell merged this into master with the merge commit 5b74696. Clicking on the commit hash there brings you to the commit detail page which will show you this information:

Commit details with branch listing

On commit pages, GitHub will list the branches and tags this commit is part of. In this case, you can see the master there, which means that this commit is part of the master branch. There are no tags listed here, so this merge commit is not part of a tag.

Looking back in the pull request, tacaswell also commented the following:

Backport notice

So he decided to backport the content of this pull request into the 2.x development line with the commit 6595139. Clicking on that hash will lead you again to the commit detail page which looks like this:

Commit details with branch/tag listing

Again, at the bottom we see the branches and tags this commit is part of. In this case, it’s again contained in the master branch, but it’s also on some branches, the bolded v2.0.2 being the most recent one, and v2.0.0b1 being the earliest. If you click on the ellipsis, you get a list of all tags this commit is on:

List of all branches and tags

If you cross-check the information you get from the GitHub web interface here with what Lasse found going the native Git way, you can see that it matches perfectly. So if you are dealing with a GitHub project and pull request anyway, you could also try to find the information on GitHub first.

poke
  • 369,085
  • 72
  • 557
  • 602
  • Great answer, and nice dive into github. Not having to clone the repository to navigate to the answer is excellent. – P-Gn Jul 24 '17 at 12:49