2015-11-04 89 views
2

我有一個與centOS系統的VPS。系統在正常情況下具有較高的負載。鍵入「cd」命令到linux git目錄時發生了什麼?

我有一個非常大(近800M)的git目錄,當我輸入命令cd到目錄時,需要花費這麼長的shell響應時間。

所以我的問題是,當我向git direcoty輸入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='\[email protected]\h:\w\[\e[1;36m\]$(parse_git_branch)\[\e[0m\]$ ' 
+0

也許是最好的* *你可以做的事情就是重構你的項目,所以沒有單獨的目錄是800MB!但是,不,我想不出任何「cd」應該是「昂貴」的原因。在「git」和/或shell中。 – paulsm4

+3

簡單的'cd'甚至不會查看目錄的內容。你必須有一個別名,或一個奇特的提示或做一些額外的工作。 –

回答

4

檢查,如果你有這可能會花費太多時間來顯示(因爲git status in a large repo can be costly

混帳PS1提示

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=": \[email protected]\h \w${this_git_status}; " 
+0

同時檢查'$ PROMPT_COMMAND' –

+0

非常感謝。我在我的bash點文件中找到了一個PS1促進器。似乎有一些緩存就像東西,當我再次進入目錄時,即使使用原點文件,響應時間也很短。我將刪除它並稍後進行測試。 – FisherMartyn