Mercurial有一种打印根目录(包含.hg)的方法

hg root

git中是否有等价的东西来获取包含.git目录的目录?


当前回答

修改一下“git配置”的答案:

git config --global --add alias.root '!pwd -P'

把道路清理干净。很好。

其他回答

从Git 2.13.0开始,它支持一个新的选项来显示根项目的路径,即使在子模块内部使用也可以工作:

git rev-parse --show-superproject-working-tree

修改一下“git配置”的答案:

git config --global --add alias.root '!pwd -P'

把道路清理干净。很好。

在这里写一个简单的答案,这样我们就可以用

git root

要完成这项工作,只需使用

git config --global alias.root "rev-parse --show-toplevel"

然后你可能想在~/.bashrc中添加以下内容:

alias cdroot='cd $(git root)'

这样你就可以用croot到回购的顶部。

git-config的手册页(在Alias下)说:

如果别名展开以感叹号作为前缀,则它将被视为外壳 命令。[…注意shell 命令将从存储库的顶级目录执行,这可能不是 必须是当前目录。

在UNIX上,你可以这样做:

git config --global --add alias.root '!pwd'
$ git config alias.root '!pwd'
# then you have:
$ git root