美文网首页
解决Mac下SourceTree pre-commit 被跳过的

解决Mac下SourceTree pre-commit 被跳过的

作者: 日不落000 | 来源:发表于2020-03-21 21:43 被阅读0次
    • 在项目中添加了pre-commit的时候格式化代码的相关配置,然后发现提交后,代码没有被格式化,然后去查看提交时的log发现以下内容:
    Can't find npx in PATH: /Applications/Xcode.app/Contents/Developer/usr/libexec/git-core:/Applications/SourceTree.app/Contents/Resources/bin:/usr/bin:/Applications/SourceTree.app/Contents/Resources/git_local/gitflow:/Applications/SourceTree.app/Contents/Resources/git_local/git-lfs:/usr/bin:/bin:/usr/sbin:/sbin
    Skipping pre-commit hook
    Completed successfully
    

    或者

    • 在Mac下使用sourcetree提交代码,出现如下报错:
    .git/hooks/pre-commit: line XXX: node: command not found
    
    

    https://stackoverflow.com/questions/12881975/git-pre-commit-hook-failing-in-github-for-mac-works-on-command-line
    中有问题分析:使用诸如SourceTree这样的gui,可以访问的环境变量不一样,需要在.git/hooks/pre-commit脚本中加入你的node环境变量

    • 首先打印你的node目录:
    $ which node
    
    

    比如(每个人的目录都不同)

    /usr/local/opt/node/bin
    
    
    • 然后将目录加入到 你的git项目下 .git/hooks/pre-commit
    # $PATH是已有目录
    PATH="/usr/local/opt/node/bin:$PATH"
    
    

    问题解决

    参考:
    Sourcetree在Mac下git pre-commit钩子无法使用node问题解决 https://www.jianshu.com/p/e70d735358eb

    相关文章

      网友评论

          本文标题:解决Mac下SourceTree pre-commit 被跳过的

          本文链接:https://www.haomeiwen.com/subject/jvfpyhtx.html