markdown 用于禁用“写入”命令的git命令的代理

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 用于禁用“写入”命令的git命令的代理相关的知识,希望对你有一定的参考价值。

# ==============================================================================
# Disable git "write" commands
# ------------------------------------------------------------------------------
git() {
    case $1 in
        add|commit|init|merge|mv|rebase|rm|tag)
            echo -e "\n!!! PLEASE DO NOT CREATE FROM THIS BOX !!!\n\n\t This is just a temp box\n\tUse a signed box instead.\n"
        ;;

        *)
            /usr/bin/git "${@}"
        ;;
    esac
}

export git
# ==============================================================================
My current laptop-of-choice is a Chromebook. This means no local software development out-of-the-box.

Thus far the Cloud9 Web IDE is a decent substitute. For quick and dirty hacking I have a specific `tmp` box.

From this box, I do not want to do any _real_ coding, just run one-off commands or do simple research.

Hence, I do not want to be able to do any git commits there.

In order to achieve this, I simply proxy the `git` command to something that tells me off for trying.

Much like my alias for `rm` protects me from accidentally deleting things from the CLI.

As aliases only work in interactive shells, I use an environment variable for this.

Environment variables are inherited by all subprocesses, this means I can't accidentally cheat this from (sub)scripts.

The command is part the `.bashrc` file in the `tmp` box

It looks like this:

    # ==============================================================================
    # Disable git "write" commands
    # ------------------------------------------------------------------------------
    git() {
        case $1 in
            add|commit|init|merge|mv|rebase|rm|tag)
                echo -e "\n!!! PLEASE DO NOT CREATE FROM THIS BOX !!!\n\n\t This is just a temp box\n\tUse a signed box instead.\n"
            ;;

            *)
                /usr/bin/git "${@}"
            ;;
        esac
    }

    export git
    # ==============================================================================

以上是关于markdown 用于禁用“写入”命令的git命令的代理的主要内容,如果未能解决你的问题,请参考以下文章

markdown 一些有用的Git命令和命令场景的Git备忘单。

markdown 使用`git flow`命令与raw`git`命令的比较。

markdown [Git常用命令] #git

markdown git命令#git #commands

markdown git有用的命令

markdown Git有用的命令