我如何判断一个提交是否是另一个提交的后代? [英] How can I tell if one commit is a descendant of another commit?
问题描述
使用Git,如何判断分支中的一个提交是否是另一个提交的后代? 如果你想要以编程方式检查(例如在脚本中),你可以检查 git merge-base AB
是否等于 git rev-parse --verify A
(然后A可以从B到达),或者如果它是 git rev-parse --verify B
(那么B可以从A到达)。 git rev-parse
需要从提交名称转换为提交SHA-1 / commit id。
使用 git rev-list
like in VonC答案也是可能的。
如果您提交的某个提交是分支提示,那么 git branch --contains< commit>
或 git branch --merged< commit>
可能是更好的非编程解决方案。
With Git, how can I tell if one commit in my branch is a descendant of another commit?
If you want to check this programmatically (e.g. in script), you can check if git merge-base A B
is equal to git rev-parse --verify A
(then A is reachable from B), or if it is git rev-parse --verify B
(then B is reachable from A). git rev-parse
is here needed to convert from commit name to commit SHA-1 / commit id.
Using git rev-list
like in VonC answer is also possibility.
If one of commits you are asking about is a branch tip, then git branch --contains <commit>
or git branch --merged <commit>
might be better non-programmatic solution.
这篇关于我如何判断一个提交是否是另一个提交的后代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!