github GUI 客户端 /dev/tty:设备未配置

Kev*_*ang 6 git github github-for-mac

我在 .git/hooks/pre-commit 中有这个预提交挂钩

#!/bin/bash
for file in `git diff --name-only`
do
  if [[ $file =~ /pom\.xml$ ]]; then
    exec < /dev/tty
    read -p "Committing $file is often a mistake; are you sure you want to do that? (Y/[N]): " ans
    exec <&-
    if [[ $ans =~ ^[Yy]$ ]]; then
      echo proceeding rashly with commit...
    else
      echo aborting commit, O prudent one.
      exit 1
    fi
  fi
done
Run Code Online (Sandbox Code Playgroud)

当我使用github for mac(GUI客户端)提交时,显示以下错误:

.git/hooks/pre-commit: line 5: /dev/tty: Device not configured
aborting commit, O prudent one.
 (1)
Run Code Online (Sandbox Code Playgroud)

它在命令行上工作。但我希望 GUI 客户端能够工作。有任何想法吗?谢谢!

Chr*_*ial 1

您的 gui 客户端不提供 tty 或任何其他方式在挂钩期间从用户获取输入。所以这是不可能的。我看到这个问题有两种解决方案:

  • 让提交通过并输出警告。回到之前的状态就像这样简单git reset HEAD^
  • 使用 git config 选项切换检查或配置有效 pom 文件的列表。