是“对我撒谎?

我通过apt-get安装了git,但是发现版本已经过时了,于是我从源代码安装了git 。 最终的结果令人费解:

 $ git --version git version 1.7.0.4 $ which git /usr/local/bin/git $ /usr/local/bin/git --version git version 1.7.6 

看来which在骗我……这似乎不太可能。 这里究竟发生了什么事情,我怎样才能让git运行正确的版本?

which是说实话。 你的shell在骗你

 git is hashed (/usr/bin/git) 

意味着你的shell已经caching了这个“git”的位置,并且正在使用cachingpath而不是再次search$ PATH。 使用hash -r清除caching,并在/usr/local/bin/git为新的git进行shellsearch$ PATH

你在shell中设置了git的别名吗?

 $ alias git="/bin/echo This is not the git you are looking for" $ which git /usr/bin/git $ git --version This is not the git you are looking for --version $ /usr/bin/git --version git version 1.7.4.1 $ type git git is aliased to `/bin/echo This is not the git you are looking for' $ unalias git $ type git git is /usr/bin/git $ git --version git version 1.7.4.1