Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I see the permission of a file in Git? [duplicate]

Tags:

git

I'd like to see the file permission as it exists in the repository index.

How can this be done?

like image 942
Chris Stryczynski Avatar asked Sep 12 '17 11:09

Chris Stryczynski


People also ask

Does git copy file permissions?

1 Answer. Show activity on this post. When Git checks out files, it by default uses the umask of the file on the system, setting the executable bit if it's a directory or it's marked as an executable file. That's because Git removes and re-creates the file, so it doesn't preserve the permissions of the existing file.

Does git change file permissions?

Git tracks exactly one bit of permission: executable or not executable. You don't say what you mean precisely by "it stopped taking file permission changes into account", but my best guess is that you didn't change the executable permission, and so from Git's point of view, there was no change to take into account.


2 Answers

Use git ls-files -s <file>:

Show staged contents' mode bits, object name and stage number in the output.

Note that Git only tracks files' executable bit. You'll only ever see 644 or 755.

like image 57
Chris Avatar answered Nov 08 '22 20:11

Chris


ls-files:

Show information about files in the index and the working tree
--stage : Show staged contents' mode bits, object name and stage number in the output.

$ git ls-files --stage 100644 b5ff1408aca94e2f33b9af9299b38764c2ec0bb7 0       .editorconfig 100644 4ef3204cd0928c0460274208c40a9e63b6c58beb 0       .gitignore 

File mode is the last 3 digits of the first number. (see index-format)

like image 28
zigarn Avatar answered Nov 08 '22 21:11

zigarn