如何在我可能位于子目录中时找到本地git存储库的路径 [英] How to find the path of the local git repository when I am possibly in a subdirectory
问题描述
我正在寻找类似于 一点背景:我已经在许多 例如,在我的主目录下( 我怎么用git命令来做到这一点? 在两种情况下,当 git list-path
来打印相关存储库的
路径( .git code $>目录)。
的存储库。
项目/文件夹中设置了git版本控制。它们中的一些是嵌套的,因此一个包含echo自己的存储库的目录是另一个用另一个存储库跟踪的目录的子文件夹。
〜
)我使用git来跟踪我的点文件,但
在文件夹〜/ photo / meta-mix /
我有另一个项目跟踪
单独的存储库。现在,我已经在目录
〜/ photo / meta-match /
中建立了另一个项目,但我不知道它是否有自己的目录
存储库。所以我想知道这个目录是否受版本
控制,以及它的存储库在哪里。
git status
可以给我
没有提交
〜/ photo / meta-match /
有自己的存储库,或者它只是指<
git rev-parse --show-toplevel
如果在git仓库中执行,就足够了。
从 git rev-parse
手册页:
- show-toplevel
显示顶级目录的绝对路径。
对于旧版本(在1.7.x之前),其他选项列在有一种方法可以在一个命令中获得git根目录吗?:
$ b $
git rev-解析--git-dir
这会给出 .git的路径目录。
运单提及:
git rev-parse --show-prefix
它返回git repo root下的本地路径。 (如果你在git repo root,则为空)
注意:只需检查一个是否在git仓库中,我发现下面的命令很有表现力:
git rev-parse --is-inside-work-tree
是的,如果您需要检查您是否位于 .git
git-dir文件夹:
git rev-parse --is-inside-git-dir
code>
I'm looking for something like git list-path
printing the
path of the associated repository (the .git
directory).
A bit of background: I have set up git version control on quite a few of my projects/folders. Some of them are nested, so one directory with echo own repository is a subfolder to another directory tracked with another repository.
E.g. in my home directory (~
) I use git to track my dot files, but
in folder ~/photo/meta-mix/
I have another project I track with a
separate repository. Now, say,I have set up another project in directory
~/photo/meta-match/
, but I don't know anymore whether it has its own
repository. So I want to find out whether this directory is version
controlled and where its repository is.
How can I do this with a git command? git status
can give me
nothing to commit
in both cases, when ~/photo/meta-match/
has its own repository or when it just refers to the repository of ~
.
git rev-parse --show-toplevel
could be enough if executed within a git repo.
From git rev-parse
man page:
--show-toplevel
Show the absolute path of the top-level directory.
For older versions (before 1.7.x), the other options are listed in "Is there a way to get the git root directory in one command?":
git rev-parse --git-dir
That would give the path of the .git
directory.
The OP mentions:
git rev-parse --show-prefix
which returns the local path under the git repo root. (empty if you are at the git repo root)
Note: for simply checking if one is in a git repo, I find the following command quite expressive:
git rev-parse --is-inside-work-tree
And yes, if you need to check if you are in a .git
git-dir folder:
git rev-parse --is-inside-git-dir
这篇关于如何在我可能位于子目录中时找到本地git存储库的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!