小编ben*_*izi的帖子

禁用特定存储库中的特定 git 命令?

最近 3 次,我在使用git. 我git reset --hard在我的主目录存储库上运行了两次。我第一次在我的 shell 中粗指了一个反向历史搜索(根本不是要运行它),第二次我在错误的终端窗口中(旨在重置不同的存储库)。另一个错误是git push --mirror ssh://remote-machine/从错误的存储库运行。

git help config 通知我“为了避免脚本使用的混淆和麻烦,隐藏现有 git 命令的别名将被忽略。”,所以我的 .git/config 别名

[alias]
reset = "!echo no"
push = "!echo wrong repo"
Run Code Online (Sandbox Code Playgroud)

被忽略。有没有办法简单地做到这一点?我可能会alias git=wrapped-git在我的 shell 中编写某种包装脚本,但我希望有一种更简单的方法来做到这一点。

更新:使用以下内容,基于grawity 的答案,但利用 git 的内置配置系统。这避免了对临时文件进行 grep'ing,并且它允许“级联”(~/.gitconfig 全局禁用“reset”,但每个 repo .git/config 启用它)。在我的 .zshrc 中:

git () {
    local disabled=$(command git config --bool disabled.$1 2>/dev/null)
    if ${disabled:-false} ; then
        echo "The $1 command is intentionally disabled" >&2
        return 1
    fi …
Run Code Online (Sandbox Code Playgroud)

git

5
推荐指数
1
解决办法
2378
查看次数

在 lsof 中查找监听通配符地址的进程

使用lsof,我可以找到所有带有 TCP 套接字侦听连接的进程:

lsof -Pni -sTCP:LISTEN

例如:

COMMAND   PID   USER  FD  TYPE  DEVICE SIZE/OFF NODE NAME
cupsd     662   root  7u  IPv6   11108      0t0  TCP [::1]:631 (LISTEN)
cupsd     662   root  8u  IPv4   11109      0t0  TCP 127.0.0.1:631 (LISTEN)
rsyncd    905   root  4u  IPv4   13379      0t0  TCP *:873 (LISTEN)
...
Run Code Online (Sandbox Code Playgroud)

有什么方法(不将输出管道传送到另一个程序,例如grep, awk, 或sed)来限制它监听通配符地址的 TCP 套接字?尝试:

$ lsof -Pni @0.0.0.0 -sTCP:LISTEN
lsof: incomplete Internet address specification: -i @0.0.0.0
Run Code Online (Sandbox Code Playgroud)

$ lsof -Pni @\* -sTCP:LISTEN
lsof: unknown host …
Run Code Online (Sandbox Code Playgroud)

tcp lsof

5
推荐指数
1
解决办法
1140
查看次数

标签 统计

git ×1

lsof ×1

tcp ×1