如何检查当前存储库是否是顶级git repo [英] How to check if the current repository is the top level git repo
问题描述
我正在尝试检查当前仓库不是子模块而是顶层
git存储库.我尝试了以下命令:git submodule init
I'm trying to check if the current repo is not a submodule but the top level
git repository. I have tried the following command: git submodule init
输出:
You need to run this command from the toplevel of the working tree.
但是它将初始化子模块.如果不是子模块而是顶层git存储库,如何在不更改存储库的情况下检查当前存储库?
But it will init the submodule. How can I check the current repository if it isn't a submodule but the top level git repository, without making a change in the repository?
推荐答案
如果您要做使用git rev-parse --show-superproject-working-tree
,请确保使用Git 2.20(2018年第四季度),以避免出现错误消息"returned path string doesn't match cwd
"
If you do use git rev-parse --show-superproject-working-tree
, make sure to use Git 2.20 (Q4 2018), in order to avoid the error message "returned path string doesn't match cwd
"
请参见提交c5cbb27 (2018年9月27日),作者为 Junio C Hamano-gitster
-在
See commit c5cbb27 (27 Sep 2018) by Sam McKelvie (sammck
).
(Merged by Junio C Hamano -- gitster
-- in commit d152a74, 19 Oct 2018)
rev-parse
:--show-superproject-working-tree应该在合并期间起作用调用'
git rev-parse --show-superproject-working-tree
'退出
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.
(这是在这里首次报道)
该问题是由于以下事实造成的:当子模块引用合并时 正在进行中时,"
git ls-files --stage —full-name <submodule-relative-path>
"为子模块返回三个单独的条目(每个阶段一个),而不是单个条目;例如,
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.
这篇关于如何检查当前存储库是否是顶级git repo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!