git submodule init
输出:You need to run this command from the toplevel of the working tree.
但是它将初始化子模块。如果当前的仓库不是子模块而是顶层git仓库,我该如何检查它,而不需要在仓库中进行更改?
git submodule init
输出: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
目前我不知道是否有一个内置的工具可以同时解决这两种情况。
git rev-parse --show-superproject-working-tree
没有返回任何输出,这正常吗? - alpergit rev-parse --show-superproject-working-tree
命令,请确保使用Git 2.20(2018年第4季度)以避免出现错误消息“returned path string doesn't match cwd
”。sammck
)于2018年9月27日提交)。
(由Junio C Hamano -- gitster
--在提交 d152a74中合并,于2018年10月19日)
这是最初在这里报道的。
rev-parse
: --show-superproject-working-tree should work during a mergeInvoking '
git rev-parse --show-superproject-working-tree
' exits with
"fatal: BUG: returned path string doesn't match cwd?"
when the superproject has an unmerged entry for the current submodule, instead of displaying the superproject's working tree.
The problem is due to the fact that when a merge of the submodule reference is in progress, "
git ls-files --stage —full-name <submodule-relative-path>
" returns three seperate entries for the submodule (one for each stage) rather than a single entry; e.g.,
$ git ls-files --stage --full-name submodule-child-test 160000 dbbd2766fa330fa741ea59bb38689fcc2d283ac5 1 submodule-child-test 160000 f174d1dbfe863a59692c3bdae730a36f2a788c51 2 submodule-child-test 160000 e6178f3a58b958543952e12824aa2106d560f21d 3 submodule-child-test
The code in
get_superproject_working_tree()
expected exactly one entry to be returned;
this patch makes it use the first entry if multiple entries are returned.