remote: error: cannot run hooks/post-receive: No such file or directory
git push 時 鈎子 post-receive 報錯 error: cannot run hooks/post-receive: No such file or directory
報錯資訊
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 334 bytes | 334.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: error: cannot run hooks/post-receive: No such file or directory
To 192.168.18.22:/work/test
93f10b9..30cc7c7 master -> master
問題分析
在 .git/hooks 下 post-receive 檔案,卻仍然報錯 No such file or directory
這種情況 是 windows 下建立的檔案或編輯的檔案,在liunx上執行導緻的,
因為各個作業系統的檔案對于換行都是不一樣的,對于DOS以及Windows作業系統是以CRLF标記換行,即一個回車+一個換行,而Linux或者Unix上面是以LF為标記的,即隻有一個換行,是以兩者的差異決定了兩個系統的檔案是不能随便移植的
解決方法
安裝 windows檔案轉linux檔案的工具 dos2unix, 然後轉換檔案
yum install dos2unix
dos2unix post-receive
結果
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 301 bytes | 301.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To 192.168.18.22:/work/test
bf30932..328dab7 master -> master