linux - 在 Linux Git 目录中输入 "cd"命令时会发生什么?

标签 linux git shell

我有一个CentOS系统的VPS。系统正常时平均负载较高。

我有一个非常大的 Git 目录(接近 800 MB)。当我在目录中输入命令 cd 时,shell 需要很长时间才能响应。

当我在 Git 目录中输入 cd 时会发生什么?我可以做什么来优化输入时间?

在此处添加我的 Bash 配置文件:

这是我的 .bash_profile 文件:

function parse_git_dirty {
    [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}

function parse_git_branch {
    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
export PS1='\u@\h:\w\[\e[1;36m\]$(parse_git_branch)\[\e[0m\]$ '

最佳答案

检查您是否有 git PS1 提示符,该提示符可能需要很长时间才能显示(因为 git status in a large repo can be costly )

See this gist例如,这有助于在执行 Ctrl+C 时禁用提示:

(摘录)

    local this_git_status=""
    if [ -z "${_skip_git_ps1}" ]; then
        this_git_status=$(__git_ps1 "(%s)")
        case $? in
            0 ) : ;;
            130 ) git_ps1_disable;; # If we break that last command because it's too slow, stop trying it
        esac
    fi
    export PS1=": \u@\h \w${this_git_status}; "

关于linux - 在 Linux Git 目录中输入 "cd"命令时会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33513367/

相关文章:

git - 首先 "git push"到远程仓库。找不到它放置项目文件的位置

git - 在 .git/hooks/pre-commit 中共享代码的好方法

linux - 通过 cronjob 中的 bash 脚本进行 sftp : 'get' and 'rm' commands not found?

bash - 如何将输出重定向到 shell 中的变量?

linux - 如何在 LUA 中添加或减去设定时间的值

linux - 仅启动了一个 screen

java - 从 C 调用 Linux 命令没有通过 java 提供任何输出

git:忽略 * 是 * 版本控制的文件

python - 在python中将带有双引号的命令传递给subprocess.call

linux - 在 Linux 上使用 JavaFX 的重音字符