Git on Windows and file attributes

2019-06-16 03:46发布

问题:

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?

Thanks.

回答1:

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).



回答2:

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.