我想要一个简单的 git 命令去到存储库的“根”。
我从一个脚本开始,但发现我无法更改 shell 的事件目录,我必须执行一个函数。不幸的是,例如,我无法使用非破折号形式“git root”直接调用它。
function git-root() {
if [ -d .git ]; then
return 0
fi
A=..
while ! [ -d $A/.git ]; do
A="$A/.."
done
cd $A
}
你有更好的解决方案吗? (功能写的很快,欢迎指教)
最佳答案
这已经被问过了,Is there a way to get the git root directory in one command?复制@docgnome 的回答,他写道
cd $(git rev-parse --show-cdup)
如果你愿意,可以做一个别名:
alias git-root='cd $(git rev-parse --show-cdup)'
关于git:一个快速命令去工作树的根,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1571461/