混帐:快速命令去工作树的根 [英] git: a quick command to go to root of the working tree
问题描述
我想一个简单的Git命令去到仓库的根。
I wanted a simple git command to go up to the "root" of the repository.
我开始用一个脚本,但想通,我不能改变外壳活动目录,我不得不做一个函数。不幸的是,我不能直接与非划线的形式混帐根称呼它,比如
I started with a script, but figured that I cannot change active directory of the shell, I had to do a function. Unfortunately, I cannot call it directly with the non-dash form "git root", for instance.
function git-root() {
if [ -d .git ]; then
return 0
fi
A=..
while ! [ -d $A/.git ]; do
A="$A/.."
done
cd $A
}
你有更好的解决办法? (该功能已经飞快地写着,建议,欢迎)
Do you have a better solution? (the function has been written quickly, suggestions are welcome)
推荐答案
这已经被问过,<一个href=\"http://stackoverflow.com/questions/957928/is-there-a-way-to-get-to-the-git-root-directory-in-one-command\">Is有没有办法让git的根目录中的一个命令?复制@ docgnome的回答,他写道:
This has been asked before, Is there a way to get the git root directory in one command? Copying @docgnome's answer, he writes
cd $(git rev-parse --show-cdup)
请一个别名,如果你喜欢:
Make an alias if you like:
alias git-root='cd $(git rev-parse --show-cdup)'
这篇关于混帐:快速命令去工作树的根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!