This is good and easy to do, in fact, with the following command:
git tag --contains f414f31
All tags for which f414f31
is one of the tag ancestors, or the tag itself indicates commit, will be listed here.
This is especially useful for determining which versions of git
contain a specific function :)
Update:
To answer the following question in the comment below:
Is there an easy way to find out all the equivalent commits that could be applied to individual branches?
You can find the hash of the patch introduced by the commit using git patch-id
- so that the git cherry
, git rebase
, etc. git rebase
used to determine if a commit has already been selected. So, if you want to know if the change f414f31
been introduced by committing to the foo
branch, you can always use a short shell script something like:
patch_id () { git show $1 | git patch-id | cut -d ' ' -f1 } P=$(patch_id f414f31) git rev-list foo | while read C do P2=$(patch_id $C) if [ x$P = x$P2 ] then echo "Also introduced by commit $C" fi done
If you want to see all the branches, you can replace foo
with --all
. Jefromi comment offers several other refinements, for example. you can add break
if you want to stop searching after the first match (reasonable if you're looking for only one branch) or exclude all the ancestors of the original commit with git rev-list foo ^f414f31
.
Jefromi's comment also reminds me that I have to say a little more about this approach. The documentation for git patch-id
explains that the generated identifier is โfairly stableโ - line numbers and spaces can change without changing the identifier, but if you had to fix any conflicts when choosing a cherry or reinstall, you can end up changing the text patch. In this case, it will not detect a commit.
I am sure that you can also do this with a git cherry
call in some way, but I can never remember in which direction the arguments should go ...;)