平时工作中,经常是在Ubuntu虚拟机下使用Git管理代码。

同时为了方便编辑,在Ubuntu上架设了Samba服务器,这样就能在Windows上访问Git代码并进行编辑。

但由于Ubuntu和Windows的文件系统操作不同,一个本来是仅有读写属性的源码文件,在Windows上修改后,就自动加上了可执行属性。

文件修改前:

$ ll mySrc.cpp

-rw-rw-r-- 1 shawn shawn 0 3月  24 09:57 mySrc.cpp

文件修改后:

$ ll mySrc.cpp

-rwxrw-r-- 1 shawn shawn 1 3月  24 09:57 mySrc.cpp*

这时如果不小心进行了提交,就会把文件的可执行属性一并提交到服务器。

一旦被爱挑毛病的老板发现,后果你懂的。

那如何能避免这个问题呢?

在git的功能设计中,已经考虑到了这种情况,在git config中有相应的设置项,如下所示,查询当前的设置项的值:

$ git config core.fileMode

true

当fileMode选项为true时,就会发生如上所述问题。我们只需把fileMode改为false即可。

$ git config core.fileMode false

注意:

执行git config时要在当前的repository内,这时配置的是local setting。

在repository之外,可以配置global或system setting。

$ git config --global core.fileMode false

$ git config --system core.fileMode false

附, 在git帮助文档中关于fileMode的说明:

core.fileMode

           Tells Git if the executable bit of files in the working tree is to be honored.

           Some filesystems lose the executable bit when a file that is marked as executable is checked out, or checks out an non-executable file with executable bit on.  git-clone(1) or git-init(1)

           probe the filesystem to see if it handles the executable bit correctly and this variable is automatically set as necessary.

           A repository, however, may be on a filesystem that handles the filemode correctly, and this variable is set to true when created, but later may be made accessible from another environment

           that loses the filemode (e.g. exporting ext4 via CIFS mount, visiting a Cygwin created repository with Git for Windows or Eclipse). In such a case it may be necessary to set this variable

           to false. See git-update-index(1).

           The default is true (when core.filemode is not specified in the config file).

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐