如何通过其SHA-1检查提交是否存在于Git存储库中 [英] How to check if the commit exists in a Git repository by its SHA-1
问题描述
在类似主题验证是否存在提交时,他们建议:
git rev-list HEAD .. $ sha
如果它没有错误代码而不存在提交,则退出。
但是验证有效吗?
我正在考虑这个选项:
git cat-file commit $ sha
code>
我的任务是否正确,还有其他想法?
您可以运行 git cat-file -t $ sha
并检查它是否返回commit。你是对的,你不需要真正的打印实际的对象...
我不是100%确定幕后发生的事情是更高效,但是。
$ b
test $(git cat-file -t $ sha)== commit
In a similar topic Validate if commit exists they recommend:
git rev-list HEAD..$sha
If it exits without error code than the commit exists.
But is it efficient enough just for validation?
I was thinking about this option:
git cat-file commit $sha
Is it correct for my task and are there any other ideas?
You can just run git cat-file -t $sha
and check it returns "commit". You are right, you don't need to actually print the actual object for that...
I'm not 100% sure that what goes on behind the scene is more efficient, though.
test $(git cat-file -t $sha) == commit
这篇关于如何通过其SHA-1检查提交是否存在于Git存储库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!