Git pre-commit hook not running on windows

前端 未结 9 861
盖世英雄少女心
盖世英雄少女心 2021-01-31 08:15

I\'m just starting to look into Git hooks, but I can\'t seem to get them to run.

I set up a local repository, so there is now a \'.git\' directory in my project folder.

相关标签:
9条回答
  • 2021-01-31 08:35

    in my case where i did npm install & accidentally deleted .git folder, npm install pre-commit --save worked

    0 讨论(0)
  • 2021-01-31 08:38

    For me i none of the above solution worked. I moved the pre-commit file from hooks to some other location, effectively deleting the file from hooks.

    That Worked for me :D

    0 讨论(0)
  • 2021-01-31 08:41

    If it helps anyone: I was getting following error:

    error: cannot spawn .git/hooks/pre-commit: No error
    

    Turned out that in my pre-commit file I did not have 'newline' character after last exit command:

    #!/bin/sh
    # From gist at https://gist.github.com/chadmaughan/5889802
    
    # stash any unstaged changes
    git stash -q --keep-index
    
    # run the tests with the gradle wrapper
    ./gradlew test --daemon
    
    # store the last exit code in a variable
    RESULT=$?
    
    # unstash the unstashed changes
    git stash pop -q
    
    # return the './gradlew test' exit code
    exit $RESULT
    # << must have a newline after above command >> 
    

    I was running gradle project on windows and gradle commands in cmder shell and cmd

    0 讨论(0)
  • 2021-01-31 08:44

    You probably don't have the permissions to run the pre-commit file

    Run in your terminal:

    chmod +x .git/hooks/pre-commit
    

    Thanks to @vaughan for giving the idea

    0 讨论(0)
  • 2021-01-31 08:46

    For me, I tried to run a .bat file.

    I discovered that backslashes need to be escaped:

    For example:

    #!/bin/bash
    C:\\somefolder\\somefile.bat
    
    0 讨论(0)
  • 2021-01-31 08:47

    Maybe it'll help someone - in my case, I had set core.hooksPath to wrong directory. Reseting it with git config --global core.hooksPath '~/.githooks' solved the issue :)

    0 讨论(0)
提交回复
热议问题