Git如何处理文件夹权限?

56
我使用的是Git版本1.5.6.3,但似乎Git没有注意到文件夹权限的变化。
#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)

04000 代表什么意思?

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

这是正常行为吗?

我该如何跟踪文件夹的模式更改?


3
相关链接:https://dev59.com/onRB5IYBdhLWcg3wCjnO如何阅读Git ls-tree命令输出的mode字段?请提供解释。 - Josh Lee
1个回答

74

git 只跟踪文件的可执行位,其余的模式位描述了每个Git树中对象的文件系统对象类型。 git 支持文件和符号链接(blob),目录(tree)和子模块(commit)。

git 设计用于帮助在不同计算机之间追踪源代码。权限位取决于各计算机之间的用户和组映射。在这些映射不存在的分布式环境中,跟踪权限位通常会妨碍事情而不是有所帮助。

如果您需要跟踪比 git 原生支持更多的文件系统属性,则可以考虑使用扩展工具,例如etckeeper


2
这不再完全准确。请参见 https://dev59.com/wVgR5IYBdhLWcg3wtfLX#40979016 - Derek Adair
1
现在Git跟踪755 vs 644(可执行或非可执行)的文件,而不是文件夹。 - Derek Adair
你说“可执行位”,但是不是有三个可执行位吗?一个是用户,一个是组,另一个是其他。Git会触及哪一位? - cowlinator

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接