git status 仅在 "Run As Administrator"时正确,这是由于 Windows VirtualStore 导致的问题

标签 git windows-8.1 uac console2

我有一个我编写的 Excel 插件的 git 存储库,因此路径是“C:\Program Files\Microsoft Office 15\root\office15\Library\BTRTools”(该“库”路径是所需的安装父级) Excel 加载项让它们正常工作,所以我无法更改它)。我在Win7和Win8.1中都打开了UAC。在 Win7 中一切正常,但是在 Win8.1 中我得到的状态基本上是“一切都改变了”(但甚至一些更奇怪的文件内容首先被提到为“已删除”,然后再次以与“未跟踪”相同的状态被提及。存储库真的是“干净”,尽管 git status 这么说,但我无法 pull 或执行重置 --hard 或任何其他操作。

如果我使用“以管理员身份运行”选项运行“Console2”(我从中发出 git bash 命令的应用程序),则一切正常且状态干净(未列出任何更改)。我可以正确执行 pull 和任何其他命令。

在 Win7 和 Win8.1 中,我已手动授予我的用户对 BTRTools 文件夹的完全访问权限(即使我已经是两者中管理员组的成员),并验证 Console2 确实作为我的本地用户运行Win8.1。

有没有人以前遇到过这个问题,并且对如何让 Console2/git 在 Win8.1 中正常工作有任何想法,而无需总是在“以管理员身份运行”模式下运行(收到提示)Console2?

提前致谢。

更新

我发现在特定条件下我在 Win7 中得到了相同的行为。我编写了一个脚本,通过创建和运行 c# Process/ProcessStartInfo 来批处理多个 git 命令,它显示的行为与 Win8.1 Console2 相同。直接在 Win7 控制台中调用完全相同的命令与在 Win7 脚本(即 git status)中调用完全相同的命令会显示两种不同的结果。

脚本(用 LINQPad 编写)以我当前的用户身份运行,但我假设当它创建并启动 Process/ProcessInfo 时,它以某种方式在不同的用户下运行。我能够通过提供我的凭据在我的脚本中纠正此问题

p.UserName = Environment.UserName;
p.Password = new System.Security.SecureString();
foreach( var c in password.ToCharArray() )
{
    p.Password.AppendChar( c );
}

注意:我验证了 Win7 和 Win8.1 中“我的”用户的安全组/设置似乎相同(管理员组的一部分)。

更新:Get-ACL 输出

我运行了 Get-ACL |两台计算机上/BTRTools 目录中的 format-list。唯一的区别是Win8对基本上所有文件夹都有“应用程序包权限”,而Win7则没有。不确定这是否暗示了什么。

更新:已解决

感谢@ian-boyd 为我指明了正确的方向。在我的 Win7 机器上,Console2/Git 工作正常,我发现我有以下文件:

C:\Users\terry.aney\AppData\Local\VirtualStore\Program Files\Microsoft Office 15\root\office15\Library\BTRTools.git\index

我不确定它是什么时候创建的。如果我删除它,Win7 上的 Console2/Git 就会开始“失败”,就像 Win8 所呈现的行为一样。我在 Win7 上恢复它,并将其复制到 Win8,现在 Console2/Win8 也能正常运行。我还有更大的战斗要打,所以我要继续前进。我不太明白这一点,但作为旁注,这里是我尝试过的一些步骤

  • 为用户组设置对\Git 安装目录的完整文件/目录访问权限 this page
  • 在#1 中的同一页面关闭将文件和注册表写入失败虚拟化到每个用户位置
  • 为用户组设置对\Library 目录的完整文件/目录访问权限。

如果有人对处理此问题的“正确”方法有任何意见,我会洗耳恭听。

最佳答案

我的猜测是 Git 尝试在它无权访问的地方写入文件。

Windows 然后尝试通过将写入重定向到其他地方来保持有问题的 Git 继续运行。检查您的

%AppData%\Local\VirtualStore

用于重定向写入的文件夹。例如:

C:\Users\Ian\AppData\Local\VirtualStore\Program Files\Microsoft Office 15\root\office 15\Library

我的猜测是您会在那里找到文件。

正确编写的 Windows 应用程序将包含一个嵌入式选项,要求 Windows重定向失败的写入。但我猜测 Git 不是一个正确编写的 Windows 应用程序。

奖金闲聊

来自Understanding and Configuring User Account Control in Windows Vista

User Account Control: Virtualize file and registry write failures to per-user locations

This setting defines virtualization settings for 32-bit applications. Virtualization does not apply to 64-bit applications.

Configuration options:

  • Enabled - If a 32-bit application with no manifest file attempts to write to a protected location like the Program Files directory, virtualization will redirect those operations to a locations in the file system and registry that all users can access. This setting enables standard users to run pre Windows Vista applications that have historically required the user running the program to be an administrator.
  • Disabled - If a 32-bit application with no manifest file attempts to write to a protected location like the Program Files directory, the write will fail and the application will silently fail to run.

Default value: Enabled

Recommendation: Keep this setting enabled in environments where software must be run that is not fully compliant with UAC. Any 32-bit non-administrative application without an application manifest file or an application database entry is not UAC compliant. Many enterprises must run pre Windows Vista software, and therefore, should keep this setting configured to Enabled.

关于git status 仅在 "Run As Administrator"时正确,这是由于 Windows VirtualStore 导致的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24705087/

相关文章:

git - 如何还原倒数第二个提交而不是最后一个提交?

java - Windows 8.1。 - Java - ODBC 驱动程序 - NetBeans

Delphi:需要时提示 UAC 提升

inno-setup - 仅在需要时使 Inno Setup 安装程序请求权限提升

git 存储库

git - 推送时自动从 GitHub 部署到服务器

c++ - 在 Windows 8.1 中运行 Visual Studio 6 C++

windows - 将整个注册表导出到相对路径

java - 尝试从 C :\ProgramData 访问文件时获取 'Access Denied'

git文件历史浏览