如何在某些Git存储库中获取Git存储库的名称? [英] How do you get the Git repository's name in some Git repository?

查看:82
本文介绍了如何在某些Git存储库中获取Git存储库的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些Git目录中工作时,如何在某些Git存储库中获取Git存储库名称?有任何Git命令吗?

When you are working in some Git directory, how can you get the Git repository name in some Git repository? Are there any Git commands?

# I did check out bar repository and working in somewhere 
# under bar directory at this moment such as below.

$ git clone git://github.com/foo/bar.git
$ cd bar/baz/qux/quux/corge/grault # and I am working in here!
$ git xxx # <- ???
bar

推荐答案

如果对于存储库名称,您的意思是Git根目录名称(包含.git目录的名称),则可以运行以下命令:

Well, if, for the repository name you mean the Git root directory name (the one that contains the .git directory) you can run this:

basename `git rev-parse --show-toplevel`

git rev-parse --show-toplevel部分为您提供了该目录的路径,而basename则除去了路径的第一部分.

The git rev-parse --show-toplevel part gives you the path to that directory and basename strips the first part of the path.

这篇关于如何在某些Git存储库中获取Git存储库的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆