我有一个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/