Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does git handle folder permission?

I'm using git version 1.5.6.3, and it seems git doesn't notice a folder's mode changes

#create a test repository with a folder with 777 mode :~$ mkdir -p test/folder :~$ touch test/folder/dummy.txt :~$ cd test :~/test$ chmod 777 folder/  #init git repository :~/test$ git init Initialized empty Git repository in ~/test/.git/ :~/test$ git add . :~/test$ git commit -m 'commit a directory' Created initial commit 9b6b21a: commit a directory  0 files changed, 0 insertions(+), 0 deletions(-)  create mode 100644 folder/dummy.txt  #change folder permission to 744 :~/test$ chmod 744 folder/ :~/test$ git status  # On branch master nothing to commit (working directory clean) 

What does 04000 stand for?

:~/test$ git ls-tree HEAD folder 040000 tree 726c1d5f0155771348ea2daee6239791f1cd7731    folder 

Is this normal behavior?

How can I track folder mode changes?

like image 887
hdorio Avatar asked Jul 01 '09 20:07

hdorio


People also ask

Does git track folder 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.

How does git store file permissions?

According to kernel.org git does not store all the permissions possible for files. Git is a content tracker, where content is de facto defined as "whatever is relevant to the state of a typical sourcecode tree". Basically, this is just files' data and "executable" attribute.

Does git care about file permissions?

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?

Yes, by default, git is configured to track the changes in file permission mode, too. Just to experiment with the idea, I created a dummy repo and "touched" an empty file. The initial default permission was 775.


1 Answers

The only 'permissions' bit that git tracks is the executable bit for files, the rest of the mode bits describe what type of file system object the object in each git tree is. git supports files and symlinks (blobs), directories (trees) and the submodules (commits).

git is designed to help track source code across different machines. Permission bits depend on user and group mappings between machines. In distributed environments where these mappings don't exist, tracking permission bits usually ends up hindering things rather than helping anything.

If you need to track more file system attributes that what git tracks natively you could consider and extension tool such as etckeeper.

like image 147
CB Bailey Avatar answered Sep 21 '22 16:09

CB Bailey