如何讓Git忽略文件模式(chmod)的變化?

我有一個項目,我必須在開發時將chmod的文件模式更改成777,但在主倉庫中不該該更改。 html

Git選擇了chmod -R 777 . 並將全部文件標記爲已更改。 有沒有辦法讓Git忽略對文件進行的模式更改? git


#1樓

若是要爲全部存儲庫設置此選項,請使用--global選項。 安全

git config --global core.filemode false

若是這不起做用,您可能正在使用更新版本的git,請嘗試使用--add選項。 ide

git config --add --global core.filemode false

若是你在沒有--global選項的狀況下運行它而且你的工做目錄不是repo,你就會獲得 this

error: could not lock config file .git/config: No such file or directory

#2樓

嘗試: spa

git config core.fileMode false

git-config(1)code

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 a 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 (eg 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).

-c標誌可用於爲一次性命令設置此選項: orm

git -c core.fileMode=false diff

而且--global標誌將使其成爲登陸用戶的默認行爲。 htm

git config --global core.fileMode false

全局設置的更改不會應用於現有存儲庫。 您必須再次克隆存儲庫或執行git init 。 這對現有存儲庫是安全的。 它不會覆蓋已存在的東西。 遞歸

警告

core.fileMode不是最佳作法,應謹慎使用。 此設置僅涵蓋模式的可執行位,而不包括讀/寫位。 在許多狀況下,您認爲您須要此設置,由於您執行了相似chmod -R 777 ,使您的全部文件均可執行。 可是在大多數項目中, 出於安全緣由,大多數文件不須要也不該該是可執行的

解決這種狀況的正確方法是分別處理文件夾和文件權限,例如:

find . -type d -exec chmod a+rwx {} \; # Make folders traversable and read/write
find . -type f -exec chmod a+rw {} \;  # Make files read/write

若是你這樣作,你將永遠不須要使用core.fileMode ,除非在很是罕見的環境中。


#3樓

添加到Greg Hewgill的回答 (使用core.fileMode配置變量):

您可使用git update-index (低級版本的「git add」)的--chmod=(-|+)x選項來更改索引中的執行權限,若是您使用「git,它將從中獲取提交「(而不是」git commit -a「)。


#4樓

若是要在遞歸的配置文件中將filemode設置爲false(包括子模塊): find -name config | xargs sed -i -e 's/filemode = true/filemode = false/' find -name config | xargs sed -i -e 's/filemode = true/filemode = false/'


#5樓

若是

git config --global core.filemode false

不起做用,手動完成:

cd into yourLovelyProject folder

cd進.git文件夾:

cd .git

編輯配置文件:

nano config

將true更改成false

[core]
        repositoryformatversion = 0
        filemode = true

- >

[core]
        repositoryformatversion = 0
        filemode = false

保存,退出,轉到上層文件夾:

cd ..

從新啓動git

git init

你完成了!

相關文章
相關標籤/搜索