What is the best way to find if a given git commit is in a tagged version

A common problem when working with fixes is to determine which fixes were fixed for fixes, i.e. this is a "patch in release X." What is the best way in git to verify that a tagged release contains a given commit id.

Manual promotion with gitk with glasses for fixing in a complex merge template is surprisingly difficult.

So far, the best solution we can offer has been to use git -cherry:

git -cherry -v $ TAG $ COMMIT $ COMMIT ^

And see if it appears with. Is there a better way?

+3
source share
1 answer

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 ...;)

+7
source

Source: https://habr.com/ru/post/917392/


All Articles