我知道在git中,我可以通过执行以下操作来获取文件的git diff:
git diff [--options] <commit> <commit> [--] [<path>...]在我的示例中:
git diff commit1 commit2 -- dirThatDoesNotExist\myFileThatDoesNotExist.txt如果路径(myFileThatDoesNotExist.txt)是一个不存在的文件,我似乎没有从git得到错误或任何其他指示,只是没有响应。
获取空响应与在有效文件中没有更改/差异是没有区别的。
如何获得指示文件路径不正确的错误消息,或者如何以其他方式区分文件名错误和有效文件名中没有更改/差异?
发布于 2018-08-29 16:44:07
你可以测试一个文件是否存在于git rev-parse commit:path的提交中。
git rev-parse commit1:myFileThatDoesNotExist.txt如果commit1中存在myFileThatDoesNotExist.txt,该命令将返回其blob sha1值,退出代码为0。如果不是,则直接返回commit1:myFileThatDoesNotExist.txt并返回退出代码128,并在标准错误中放入一条错误消息,说明fatal: Path 'myFileThatDoesNotExist.txt' does not exist in 'commit1'
if git rev-parse commit1:myFileThatDoesNotExist.txt || git rev-parse commit2:myFileThatDoesNotExist.txt;then
# exist in one of the two commits or in both
git diff commit1 commit2 -- myFileThatDoesNotExist.txt
else
# exist in neither, do something else
:
fihttps://stackoverflow.com/questions/52071860
复制相似问题