git 存储库是否有命名约定?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11947587/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:23:44  来源:igfitidea点击:

Is there a naming convention for git repositories?

gitgithubnaming-conventions

提问by Adrian M

For example, I have a RESTful service called Purchase Service. Should I name my repository:

例如,我有一个名为 Purchase Service 的 RESTful 服务。我应该命名我的存储库:

  1. purchaserestservice
  2. purchase-rest-service
  3. purchase_rest_service
  4. or something else?
  1. purchaserestservice
  2. purchase-rest-service
  3. purchase_rest_service
  4. 或者是其他东西?

What's the convention? How about in Github? Should public repositories follow some standard?

约定是什么?在 Github 上呢?公共存储库应该遵循一些标准吗?

回答by Aaron Digulla

I'd go for purchase-rest-service. Reasons:

我会去purchase-rest-service。原因:

  1. What is "pur chase rests ervice"? Long, concatenated words are hard to understand. I know, I'm German. "Donaudampfschifffahrtskapit?nspatentausfüllungsassistentenausschreibungsstellenbewerbung."

  2. "_" is harder to type than "-"

  1. 什么是“采购休息服务”?长的、连接的单词很难理解。我知道,我是德国人。“Donaudampfschifffahrtskapit?nspatentausfüllungsassistentenausschreibungsstellenbewerbung。”

  2. “_”比“-”更难输入

回答by Matthew Sandoz

The problem with camel case is that there are often different interpretations of words - for example, checkinService vs checkInService. Going along with Aaron's answer, it is difficult with auto-completion if you have many similarly named repos to have to constantly check if the person who created the repo you care about used a certain breakdown of the upper and lower cases. avoid upper case.

驼峰式大小写的问题在于对单词的解释通常不同 - 例如,checkinService 与 checkInService。按照 Aaron 的回答,如果您有许多类似命名的存储库,必须不断检查创建您关心的存储库的人是否使用了大写和小写的特定细分,那么自动完成是很困难的。避免大写。

His point about dashes is also well-advised.

他关于破折号的观点也是明智的。

  1. use lower case.
  2. use dashes.
  3. be specific. you may find you have to differentiate between similar ideas later - ie use purchase-rest-service instead of service or rest-service.
  4. be consistent. consider usage from the various GIT vendors - how do you want your repositories to be sorted/grouped?
  1. 使用小写。
  2. 使用破折号。
  3. 请明确点。您可能会发现以后必须区分类似的想法 - 即使用购买-休息-服务而不是服务或休息-服务。
  4. 始终如一。考虑各种 GIT 供应商的使用情况 - 您希望如何对存储库进行排序/分组?

回答by Dennis

lowercase-with-hyphensis the style I most often see on GitHub.*

lowercase-with-hyphens是我在 GitHub 上最常看到的风格。*

lowercase_with_underscoresis probably the second most popular style I see.

lowercase_with_underscores可能是我看到的第二流行的款式。

The former is my preference because it saves keystrokes.

前者是我的首选,因为它可以节省击键次数。

* Anecdotal; I haven't collected any data.

* 轶事;我没有收集任何数据。

回答by VonC

Without favouring any particular naming choice, remember that a git repo can be cloned into any root directory of your choice:

在不支持任何特定命名选择的情况下,请记住,可以将 git repo 克隆到您选择的任何根目录中:

git clone https://github.com/user/repo.git myDir

Here repo.gitwould be cloned into the myDirdirectory.

这里repo.git将被克隆到myDir目录中。

So even if your naming convention for a public repo ended up to be slightly incorrect, it would still be possible to fix it on the client side.

因此,即使您的公共存储库命名约定最终有点不正确,仍然可以在客户端修复它。

That is why, in a distributedenvironment where any client can do whatever he/she wants, there isn't really a naming convention for Git repo.
(except to reserve "xxx.git" for bareform of the repo 'xxx')
There might be naming convention for REST service (similar to "Are there any naming convention guidelines for REST APIs?"), but that is a separate issue.

这就是为什么在分布式环境中,任何客户端都可以为所欲为,Git 存储库并没有真正的命名约定。
(除了为repo ' ' 的形式保留“ xxx.git” ) REST 服务可能有命名约定(类似于“是否有任何 REST API 命名约定指南?”),但这是一个单独的问题。xxx

回答by SteveW

Maybe it is just my Java and C background showing, but I prefer CamelCase (CapCase) over punctuation in the name. My workgroup uses such names, probably to match the names of the app or service the repository contains.

也许这只是我的 Java 和 C 背景显示,但我更喜欢 CamelCase (CapCase) 而不是名称中的标点符号。我的工作组使用这样的名称,可能是为了匹配存储库包含的应用程序或服务的名称。

回答by Adam

If you plan to create a PHP package you most likely want to put in on Packagistto make it available for other with composer. Composer has the as naming-conventionto use vendorname/package-name-is-lowercase-with-hyphens.

如果您打算创建一个 PHP 包,您很可能希望将它放在Packagist上,以便其他人使用Composer。作曲家有作为命名,约定在使用vendorname/package-name-is-lowercase-with-hyphens

If you plan to create a JS package you probably want to use npm. One of their naming conventionsis to not permit upper case letters in the middle of your package name.

如果你打算创建一个 JS 包,你可能想使用 npm。它们的命名约定之一是不允许在包名称中间使用大写字母。

Therefore, I would recommend for PHP and JS packages to use lowercase-with-hyphensand name your packages in composer or npm identically to your package on GitHub.

因此,我建议 PHP 和 JSlowercase-with-hyphens包在 composer 或 npm 中使用和命名你的包,与你在 GitHub 上的包相同。