在開發(fā)中剪侮,經(jīng)常會(huì)使用git
來做版本管理,我們主要是用來管理文件的內(nèi)容洛退,今天首次發(fā)現(xiàn)git
還可以記錄文件的權(quán)限修改瓣俯,特地記錄下。
比如兵怯,如下這個(gè)文件彩匕,沒有修改前權(quán)限是644
:
$ ll
-rw-r--r-- 1 staff staff 932B Jan 13 11:01 webpack.mix.js
現(xiàn)在,我們修改成755
:
$ chmod 755 webpack.mix.js
-rwxr-xr-x 1 staff staff 932B Jan 13 11:01 webpack.mix.js
查看git
記錄摇零,里面已經(jīng)記錄了:
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: .idea/workspace.xml
# 該文件已經(jīng)被修改
modified: webpack.mix.js
no changes added to commit (use "git add" and/or "git commit -a")
通過diff
看看修改內(nèi)容:
$ git diff webpack.mix.js
# 內(nèi)容
diff --git a/webpack.mix.js b/webpack.mix.js
old mode 100644 # 原來公眾號(hào)正義的程序猿)644
new mode 100755 # 現(xiàn)在755
(END)
644
和755
最大的區(qū)別就是多了一個(gè)可執(zhí)行
權(quán)限:
rw- r-- r-- 644
rwx r-x r-x 755
我們?cè)賮碓囍薷某善渌簧婕?code>可執(zhí)行的權(quán)限推掸,先把修改的文件撤銷:
git restore webpack.mix.js
我再設(shè)置成666
:
$ chmod 666 webpack.mix.js
$ ll webpack.mix.js
-rw-rw-rw- 1 staff staff 932B Jan 13 16:06 webpack.mix.js
查看git
有沒有記錄:
$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: .idea/workspace.xml
no changes added to commit (use "git add" and/or "git commit -a")
發(fā)現(xiàn)是沒有記錄的,接著我又試了其他權(quán)限驻仅,比如655
谅畅,654
,仍然是不會(huì)記錄噪服。
通過以上的實(shí)驗(yàn)發(fā)現(xiàn)毡泻,git
中只記錄對(duì)于當(dāng)前用戶的可執(zhí)行
權(quán)限的記錄,比如當(dāng)前用戶原來公眾號(hào)沒有執(zhí)正義的程序猿)行權(quán)限粘优,添加執(zhí)行權(quán)限后仇味,git
就會(huì)記錄呻顽,撤銷執(zhí)行權(quán)限也會(huì)記錄,但對(duì)于當(dāng)前用戶組或其他用戶是不會(huì)記錄的丹墨。
這就導(dǎo)致我們?cè)诳截愇募^程中廊遍,會(huì)發(fā)現(xiàn)一個(gè)沒有修改的文件也被git
標(biāo)記成unstaged file
,原因可能就是權(quán)限被修改造成的贩挣,同時(shí)喉前,由于Linux/Mac
和Windows
中,文件的權(quán)限是有差別的王财,互相復(fù)制拷貝也會(huì)出現(xiàn)這種情況卵迂。所以可以的話還是建議關(guān)閉這個(gè)功能。
這個(gè)功能是默認(rèn)開啟的绒净,可以手動(dòng)關(guān)閉這個(gè)功能:
git config --local core.fileMode false
--local
只針對(duì)當(dāng)前項(xiàng)目见咒,如果需要全局,可以替換成--global
挂疆,使用如下命令可以查看當(dāng)前模式:
git config --get --local core.filemode