10

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?

Nimantha
  • 6,405
  • 6
  • 28
  • 69
StockBreak
  • 2,857
  • 1
  • 35
  • 61

3 Answers3

10

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

Cat Plus Plus
  • 125,936
  • 27
  • 200
  • 224
  • Ok, thank you for the clear answer. I have few hidden and read-only files in my project but I will change them by hand if necessary. – StockBreak Jan 03 '12 at 16:25
  • 1
    I would like this feature too, it is not "downright useless". For example, the Unity game development environment creates a sidecar ".meta" file for managing it's scene database. These files need to be revisioned, but no human ever needs to see them. – yoyo Jan 23 '12 at 18:38
  • I would also find this useful. I develop with the node/grunt/bower toolchain under VisualStudio and setting the node_modules and bower_components folder to hidden, stop VS from indexing and searching (and even showing) those in the solution explorer, which is quite important for a smooth development. – Daniel Sep 29 '14 at 07:05
9

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.

earcam
  • 6,662
  • 4
  • 37
  • 57
wadesworld
  • 13,535
  • 14
  • 60
  • 93
1

I tried @wadesworld suggestion and came up with this, Create the file \.git\hooks\post-checkout with the content:

#!/usr/bin/env pwsh
param (
    $PreviousHead,
    $NewHead,
    # Branch 1, File 0.
    $BranchOrFile
)
$Name = '.HideMe'
if ((Test-Path $Name) -and !(Get-Item $Name -Force).Attributes.HasFlag([IO.FileAttributes]::Hidden)) {
    (Get-Item $Name).Attributes += 'Hidden'
}

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.

ili
  • 405
  • 4
  • 6