[Git] 檔案權限改變,導致所有的檔案都被 Git 視為已修改?

[Git] 檔案權限改變,導致所有的檔案都被 Git 視為已修改?

今天把一個 Git repository 移到某個隨身硬碟上,

不知道為什麼,檔案的權限全都變成 777 (rwx) 全開:

testuser@localhost ~ $ ll

-rwxrwxrwx  1 testuser  staff      11 Jun 30 17:02 README.md*
drwxrwxrwx  1 testuser  staff  131072 Jun 30 16:55 Project/

 

這時候用 git status 指令的話,

會發現幾乎所有的檔案都被列在「已修改」的狀態:

testuser@localhost ~ $ git status

On branch bug/fix-performance-drop
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

	modified:   .gitattributes
	modified:   .github/CODEOWNERS
	modified:   .gitignore
	modified:   README.md
	modified:   Project/3rd_party/7zip/7-zip.chm
	modified:   Project/3rd_party/7zip/license.txt
    ......

 

當然檔案權限的問題需要解決,

但這次我移到隨身硬碟,只是為了做個備份,

因此我希望 git status 還是可以正常運作,

不要因為檔案權限的改變,就把它列為「已修改」…

 

上網查,如果是將 Windows 的檔案掛載到 Linux (或是反過來),

也是有可能會遇到類似的問題…

這時候可以調整 git 的 core.filemode 設定,將其關閉:

git config core.filemode false

 

這時 git status 就不會管檔案權限的改變,

只有檔案內容有修改的,才會被列在「已修改」的區域囉:

testuser@localhost ~ $ git status

On branch bug/fix-performance-drop
Untracked files:
  (use "git add ..." to include in what will be committed)

	._.DS_Store

 

參考資料:git status shows all files as modified · Issue #184 · microsoft/WSL

(本頁面已被瀏覽過 1,009 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料