Stumbled across this error today to waste a good amount of time, while trying to have gerrit hook setup for a repository, was using the following command scp -p -P 29418 tttt@tttt.ttt.com:hooks/commit-msg .git/hooks/ on terminal after having checked-out the project via XCode
Two reasons for this are:
- Executing hook command on incorrect folder. Makes sure to execute this command on
parentfolder of thechecked-outfolder & not onchecked-outfolder. - Executing hook on a different branch other than on the
masterbranch. Make sure to run the hook command on themasterbranch, before switching/checking-out a different branch.
Make sure that you are trying to install the hook from the correct folder, which is the root folder of the repository (which contains the .git folder)
In my case, I have cloned the repo using SourceTree, which omitted putting the repo inside a root folder. So, there were a bunch of files inside a folder that I have manually created on Finder.
To fix it, I re-cloned the project through the terminal, it puts the files inside a root folder with the name of the project; then everything worked fine.
来源:https://stackoverflow.com/questions/31854122/git-hooks-no-such-file-or-directory-protocol-error-expected-control-record