Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git on Windows and file attributes

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?

like image 579
StockBreak Avatar asked Jan 03 '12 16:01

StockBreak


3 Answers

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.

like image 198
ili Avatar answered Oct 19 '22 03:10

ili


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

like image 28
Cat Plus Plus Avatar answered Oct 19 '22 04:10

Cat Plus Plus


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.

like image 9
wadesworld Avatar answered Oct 19 '22 03:10

wadesworld