什么是最好的方式来查找给定的git提交是否在标签发布中 [英] What's the best way to find if a given git commit is in a tagged release

查看:143
本文介绍了什么是最好的方式来查找给定的git提交是否在标签发布中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

处理修复时遇到的一个常见问题是计算出修复已经应用到的版本,即这是X版本中的修复。 git中检查标签版本包含给定提交ID的最佳方法是什么?



使用gitk手动浏览复杂合并模式中的提交非常困难。

到目前为止,我们可以想到的最好的解决方案是使用git-cherry:

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



然后看看是否出现了 - 。有没有更好的方法?

解决方案

实际上,使用以下命令很容易:

  git tag --contains f414f31 

这将列出所有标签,使得 f414f31 是其中一个标签的祖先,或者标签本身指向该提交。



这对于查找哪些版本的 git 包含特定功能特别有用:)



要回答下面评论中的其他问题: p>


是否有任何简单的方法可以找出所有可能应用于单独分支的等价提交?

你可以通过使用 git patch-id 找到提交引入的补丁的哈希值, git cherry git rebase 等用于查找提交是否具有已经被樱桃采摘了。因此,如果您想要查找由 f414f31 引入的更改是否也由分支 foo 上的提交引入的,你可以使用一个简短的shell脚本,例如:

  patch_id(){
git show $ 1 | git patch-id | cut -d''-f1
}

P = $(patch_id f414f31)

git rev-list foo |同时读取C
do
P2 = $(patch_id $ C)
if [x $ P = x $ P2]
then
echo C
fi
完成

如果您想查看所有分支,你可以用 - all 替换 foo 。下面的 Jefromi 的评论暗示了其他一些改进,例如你可以添加一个 break ,如果你想停下来看看第一个匹配(如果你只搜索一个分支是明智的),或者排除原始提交的所有祖先使用 git rev-list foo ^ f414f31 代替。



Jefromi的评论也提醒我应该多说一点关于这种方法。 git patch-id 文档c> 解释了生成的ID是相当稳定的 - 行号和空白可以在不影响ID的情况下进行更改,但是如果您必须在cherry-pick或rebase期间修复任何冲突,则最终可能会更改补丁的文本。在这种情况下,这不会找到提交。



我相信你也可以通过调用 git cherry 不知何故,但我永远不会记得参数意味着什么方向......;)


A common problem when dealing with fixes is to work out what releases given fixes have been applied to, i.e "is this fix in release X". What's the best way in git to check what tagged release contains a given commit id.

Going through with gitk manually eye-balling a commit in a complex merge pattern is surprisingly hard.

So far the best solution we can come up with has been to use git-cherry:

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

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

解决方案

This is nice and easy to do, in fact, with the following command:

git tag --contains f414f31

That will list all the tags such that f414f31 is one of the tag's ancestors, or the tag itself points to that commit.

This is particularly useful for finding which versions of git contain a particular feature :)


Update:

To answer a further question in the comment below:

Is there any easy way to find out all the equivalent commits that may have been applied to separate branches?

You can find a hash of the patch introduced by the commit by using git patch-id - that's the command that git cherry, git rebase, etc. use to find whether a commit has already been cherry-picked. So, if you want to find whether the change introduced by f414f31 was also introduced by a commit on the branch foo, you could 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 look across all branches, you can replace foo with --all. Jefromi's comment below suggests a couple of other refinements, e.g. you can add a break if you want to stop looking after the first match (sensible if you're only searching a single branch), or exclude all ancestors of the original commit by using git rev-list foo ^f414f31 instead.

Jefromi's comment also reminds me that I should say a bit more about this approach. The documentation for git patch-id explains that the ID generated is "reasonably stable" - the line numbers and whitespace can change without affecting the ID, but if you had to fix any conflicts during the cherry-pick or rebase, you may end up changing the text of the patch. In that case, this wouldn't find the commit.

I'm sure you can also do this with an invocation of git cherry somehow, but I can never remember which way round the arguments are meant to go... ;)

这篇关于什么是最好的方式来查找给定的git提交是否在标签发布中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆