Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PowerShell检查Git暂存区域中的xml文件_Git_Powershell - Fatal编程技术网

使用PowerShell检查Git暂存区域中的xml文件

使用PowerShell检查Git暂存区域中的xml文件,git,powershell,Git,Powershell,我将Git用于ASP.Net网站,其密码存储在web.config文件中。为了防止它们被提交,我设置了配置部分加密,这样文件的connectionStrings部分就被加密了——除非我对它进行解密以使其无所事事 然后,为了防止意外提交未加密的文件,我编写了一个小的PowerShell脚本,本地预提交钩子将调用该脚本: # Verifies that web.config's connectionStrings is encrypted. [xml]$config = get-content .

我将Git用于ASP.Net网站,其密码存储在web.config文件中。为了防止它们被提交,我设置了配置部分加密,这样文件的
connectionStrings
部分就被加密了——除非我对它进行解密以使其无所事事

然后,为了防止意外提交未加密的文件,我编写了一个小的PowerShell脚本,本地预提交钩子将调用该脚本:

# Verifies that web.config's connectionStrings is encrypted.

[xml]$config = get-content .\Code\SlicerWeb\web.config
if ($config.configuration.connectionStrings.EncryptedData) {
    exit 0
    }
else {
    Write-Output "connectionStrings section is not encrypted."
    exit 1
    }
这很好,而且可能已经足够好了。但现在我意识到我真正应该做的是检查索引(暂存区域)中文件的内容,而不是磁盘上的当前文件


如何才能在索引中获取文件的内容?

您可以使用:前缀访问当前索引中的对象。所以这应该行得通

[xml]$config = git show :./Code/SlicerWeb/web.config
(路径中的反斜杠在此不起作用)