我正在尝试检查当前的存储库是否不是子模块而是顶层
git 存储库。我尝试过以下命令:git submodule init
Output:
You need to run this command from the toplevel of the working tree.
但它会初始化子模块。如果当前存储库不是子模块而是顶级 git 存储库,如何在不更改存储库的情况下检查当前存储库?
你可能想要git rev-parse --show-superproject-working-tree
,并回退到git rev-parse --show-toplevel
如果您不在子模块中。例如:
toplevel=$(git rev-parse --show-toplevel)
superproject=$(git rev-parse --show-superproject-working-tree)
if [[ -z "$superproject" ]]; then
echo "submodule in $superproject"
else
echo "toplevel is $toplevel"
fi
目前我还不知道有哪个内置函数可以为这两种情况提供一体化的答案。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)