gip*_*any 119 git repository
当您在某个Git目录中工作时,如何在某些Git存储库中获取Git存储库名称?有没有Git命令?
# 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
Fua*_*aud 134
好吧,如果,对于存储库名称,您指的是Git根目录名称(包含.git目录的名称),您可以运行此命令:
basename `git rev-parse --show-toplevel`
该git rev-parse --show-toplevel部分为您提供该目录的路径,并basename删除路径的第一部分.
mvp*_*mvp 112
一般来说,你不能这样做.Git并不关心如何命名你的git存储库.例如,您可以重命名包含您的存储库的目录(一个包含.git子目录),git甚至不会注意到它 - 一切都将继续工作.
但是,如果您克隆它,则可以使用命令:
git remote show origin
显示有关您从中克隆存储库的原始远程的大量信息,它将包含原始克隆URL.
但是,如果您删除了使用原始远程的链接git remote rm origin,或者如果您使用创建该存储库git init,则无法获取此类信息 - 它在任何地方都不存在.
Tas*_*eat 68
无需联系存储库即可获取名称,文件夹名称不一定反映远程名称.
我发现这是获取当前存储库名称的最准确和有效的方法:
basename -s .git `git config --get remote.origin.url`
这应该与Git 1.8.1.5一样.在此之前,现在已弃用的git-repo-config命令将起作用(早在Git 1.7.5).
vul*_*ven 21
在git v2.7.0 +中,get-url引入了一个子命令来git-remote命令.
POSIX shell:
basename $(git remote get-url origin)
电源外壳:
Split-Path -Leaf (git remote get-url origin)
dra*_*agn 18
当您的目录名称与远程存储库名称不对应时,其他答案仍然无效(并且可能).您可以使用以下内容获取存储库的真实名称:
git remote show origin -n | grep "Fetch URL:" | sed -E "s#^.*/(.*)$#\1#" | sed "s#.git$##"
基本上,你叫git remote show origin,从"获取URL:"拿仓库URL字段,正则表达式,它获得与名称的部分:
 https://github.com/dragn/ 整齐-的vimrc的.git
ani*_*gif 17
如果您尝试在 github 上获取用户名或组织名称以及项目或存储库名称,我可以编写此命令,该命令至少在本地对我有用。
? git config --get remote.origin.url
# => https://github.com/Vydia/gourami.git
? git config --get remote.origin.url | sed 's/.*\/\([^ ]*\/[^.]*\).*/\1/' # Capture last 2 path segments before the dot in .git
# => Vydia/gourami
这是所需的结果,Vydia组织名称gourami也是包名称。结合它们可以帮助形成完整的User/Repo路径
这个问题有点晚了,但如果你:
cat /path/to/repo/.git/config
您将看到存储库的 url,其中将包含 reponame:
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = https://github.com/your_git_user_name/your_git_repo_name.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
| 归档时间: | 
 | 
| 查看次数: | 153845 次 | 
| 最近记录: |