【问题标题】:What happens when typing the "cd" command to a Linux Git directory?在 Linux Git 目录中输入“cd”命令会发生什么?
【发布时间】:2015-11-04 03:53:30
【问题描述】:

我有一个带有 CentOS 系统的 VPS。系统正常时loadavg较高。

我有一个非常大的 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\]$ '

【问题讨论】:

  • 也许你能做的最好的事情就是重构你的项目,所以没有一个目录是800MB!但是不,我想不出任何理由“cd”应该是“昂贵的”。在“git”和/或 shell 中。
  • 普通的cd 甚至不会查看目录的内容。你必须有一个别名,或者一个花哨的提示或者做一些额外的工作。

标签: linux git shell


【解决方案1】:

检查你是否有一个 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}; "

【讨论】:

  • 同时检查$PROMPT_COMMAND
  • 非常感谢。我确实在我的 bash 点文件中找到了 PS1 促销。好像有一些类似缓存的东西,当我再次进入目录时,即使使用原始点文件,响应时间也很短。我将删除它并稍后测试它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-23
  • 2019-01-19
  • 2015-01-01
  • 2023-02-01
  • 2015-07-15
  • 1970-01-01
  • 2016-11-05
相关资源
最近更新 更多