Windows 上的 Git 和文件属性
我注意到,当您在 Windows 环境中使用 Git 提交或签出文件时,文件属性不会保留(例如隐藏或只读)。如果我提交一个隐藏文件,然后在另一台计算机上查看它,则该文件不再是隐藏的。是否可以让 Git 识别 Windows 文件属性?
I noticed that when you commit or checkout files using Git in a Windows environment, the file attributes are not preserved (for example hidden or read-only). If I commit a hidden file and then I check it out on another computer, the file is no more hidden. Is it possible to make Git recognize Windows file attributes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不会。Git 也不跟踪完整的 UNIX 权限,它只是为了方便而记住可执行位。至于为什么——它是一个版本控制系统,旨在主要跟踪源代码。这使得该功能完全无用(更不用说“隐藏”属性本身也毫无用处)。
No. Git doesn't track full UNIX permissions either, it just remembers the executable bit for convenience. As to why — it's a version control system, designed to track primarily source code. Which makes that feature downright useless (not to mention 'hidden' attribute is quite useless on its own, too).
您可以使用结帐后客户端挂钩进行任何需要的更改。在您的情况下,您将使用它来运行一个脚本来设置您想要的 Windows 文件属性。
ProGit 在“其他客户端挂钩”段落中对此进行了一般性描述:
自定义 Git 挂钩
另请参阅 githooks 手册页。
You can use the post-checkout client-side hook to make any changes you need to make. In your case, you'd use it to run a script which sets the Windows file attributes you want.
ProGit describes this in general terms in the "Other Client Hooks" paragraph:
Customizing Git Hooks
Also, see githooks man page.
我尝试了 @wadesworld 建议并提出了这个,创建文件
\.git\hooks\post-checkout
其内容:将
.HideMe
更改为您的文件/文件夹如果需要隐藏,您还可以使用 3 个参数,例如仅在分支签出或文件签出时运行。这需要安装 PowerShell Core 才能工作,但也可以在 cmd 或 Windows PowerShell 中实现。I tried @wadesworld suggestion and came up with this, Create the file
\.git\hooks\post-checkout
with the content:Change
.HideMe
to the file/folder you want to hide, you can also use the 3 parameters if needed, like for example run only on branch checkout or file checkout. This needs PowerShell Core installed to work but could probably be implemented in cmd or Windows PowerShell as well.