Git忽略文件权限修改

我们在使用Git进行版本管理的时候,有时候只是修改了文件的权限,比如将Runtime修改为777,但其实文件内容并没有改变,但是git会认为此文件做了修改,原因是git把文件权限也算作文件差异的一部分了。如下:

[root@localhost www]# git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#    modified:   .gitignore
#    modified:   App/Conf/config.ini.php
#    modified:   App/Runtime/Cache/240489da0c6c6389a269aca80da3a2e4.php
#    modified:   App/Runtime/Cache/3b8f0dc8ea54082c2d25ce0555166880.php
#    modified:   App/Runtime/Cache/42d800574ff2aff20e3f49c56cd8fd5a.php
#    modified:   App/Runtime/Cache/59018fa70b9bd403513b8a90c20171a2.php
#    modified:   App/Runtime/Cache/f331a3f0d874c4248458495ef2c2c2d1.php
#    modified:   App/Runtime/Logs/17_03_29.log
#    modified:   App/Runtime/Logs/17_04_12.log
#    modified:   App/Runtime/Logs/17_04_13.log
#    modified:   App/Runtime/Logs/17_04_14.log

解决办法:

git中可以加入忽略文件权限的配置,如下:

$ git config core.filemode false

这样就设置了忽略文件权限。查看下配置:

[root@localhost www]# cat .git/config
[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true

重新查看git status:

[root@localhost www]# git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#    modified:   .gitignore
#    modified:   App/Conf/config.ini.php

这时候Git忽略文件权限修改已经完成。

本文链接:https://jeff.xin/post/63.html

--EOF--

Comments

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。