How to list all tags that contain a commit?
Asked Answered
B

2

315

This question is similar to How to list all tags pointing to a specific commit in git, but with one difference: I wish to search for all tags that contain a specific commit within the tree of each tag, not specifically the files marked in the tag itself (in this case, only the Makefile change has been tagged).

Blindheim answered 27/10, 2011 at 22:13 Comment(4)
You can't tag a particular file - tags only point to commits. You might want to edit your question with more details of the problem that you're really trying to solve.Barbour
See also: How to list branches that contain a given commit.Archaimbaud
Note: on Windows, make sure to use git 2.0.x (2014) if you want git tag --contains to not crash. See my answer belowAfrika
There is also git branch --contains <commit> which does the same for branches. Needed both at the same time.Teraterai
M
497
git tag --contains <commit>
Mucronate answered 27/10, 2011 at 22:16 Comment(6)
I've tried this. But if the tag only contains one file, I believe it only searches through that file. It won't search the tree. Also, the repository I tried it on is so large git bailed and got SIGKILL'ed.Blindheim
Tags don't contain files. They're just markers for a commit. Given that, I don't think your objection makes sense.Mucronate
It must not be showing me the commit because of lack of memory in that case. Do you know how I can get over this?Blindheim
Is there any way to do this against remote tags? Similar to with branches: git branch -r --contains <commit>Lugworm
note that this command can not be always trusted. See stackoverflow.com/questions/16304574/…Caladium
@gatispaeglis That link is about a different question. If you want to find tags containing a commit, this is how you do it. Finding commits with an identical diff is a different thing, and not very common to need. The answer you link to would be terrible advice to give to someone who just wants to find tags containing an actual commit.Mucronate
A
30

Note that you need git 2.0.x (Q3 2014) in order to list all tags for a certain commit if you have a large repo

See commit cbc60b6 by Jean-Jacques Lafay (lanfeust69):

git tag --contains: avoid stack overflow

In large repos, the recursion implementation of contains(commit, commit_list) may result in a stack overflow. Replace the recursion with a loop to fix it.

This problem is more apparent on Windows than on Linux, where the stack is more limited by default.

See also this thread on the msysGit list.

Afrika answered 26/7, 2014 at 18:28 Comment(2)
No pun intended? ;-)Damal
@Damal Well... not an intentional one, at least.Afrika

© 2022 - 2024 — McMap. All rights reserved.