有没有一个git命令返回当前的项目名称? [英] Is there a git command that returns the current project name?

查看:221
本文介绍了有没有一个git命令返回当前的项目名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git是否有一个内置命令来显示当前远程项目的名称?现在我使用这个:

  git remote -v |头-n1 | awk'{print $ 2}'| sed's /.* \ ///'| sed's / \.git //'

...但好像会有一个内置的等价物。

解决方案

看起来您的脚本正在拉动远程URL的最后部分,并将其用作项目名。这适用于使用单个远程站点(例如 http://bitbucket.org ),但是您的系统无法在该存储库的所有用户中普遍使用。

用户通常都有不同的远程存储库,事实上在许多项目中,您将拥有多个远程存储库。在获取和合并时,Git不关心仓库的来源。合并算法甚至会接受没有共同祖先的分支。

唯一真正的解决方案是在包含项目名称的每个存储库的根目录中创建一个文本文件。无论他们如何设置遥控器,该解决方案都适用于所有用户。


Does git have a built-in command for showing the name of the current remote project? Right now I'm using this:

git remote -v | head -n1 | awk '{print $2}' | sed 's/.*\///' | sed 's/\.git//'

...but it seems like there would be a built-in equivalent.

解决方案

It looks like your script is pulling the last part of the remote URL and using that as the project name. This works when using a single remote site, such as http://bitbucket.org but your system will not work universally across all users of that repository.

Users generally all have different remote repositories, in fact on many projects you will have multiple remotes. Git does not care where a repository comes from when fetching and merging. The merge algorithm will even accept branches with no common ancestor.

The only real solution is to create a text file in the root of each repository that contains the project name. This solution will work across all users, regardless of how they setup their remotes.

这篇关于有没有一个git命令返回当前的项目名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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