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
Is there a naming convention for git repositories?
提问by Adrian M
For example, I have a RESTful service called Purchase Service. Should I name my repository:
例如,我有一个名为 Purchase Service 的 RESTful 服务。我应该命名我的存储库:
purchaserestservice
purchase-rest-service
purchase_rest_service
- or something else?
purchaserestservice
purchase-rest-service
purchase_rest_service
- 或者是其他东西?
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
。原因:
What is "pur chase rests ervice"? Long, concatenated words are hard to understand. I know, I'm German. "Donaudampfschifffahrtskapit?nspatentausfüllungsassistentenausschreibungsstellenbewerbung."
"_" is harder to type than "-"
什么是“采购休息服务”?长的、连接的单词很难理解。我知道,我是德国人。“Donaudampfschifffahrtskapit?nspatentausfüllungsassistentenausschreibungsstellenbewerbung。”
“_”比“-”更难输入
回答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.
他关于破折号的观点也是明智的。
- use lower case.
- use dashes.
- be specific. you may find you have to differentiate between similar ideas later - ie use purchase-rest-service instead of service or rest-service.
- be consistent. consider usage from the various GIT vendors - how do you want your repositories to be sorted/grouped?
- 使用小写。
- 使用破折号。
- 请明确点。您可能会发现以后必须区分类似的想法 - 即使用购买-休息-服务而不是服务或休息-服务。
- 始终如一。考虑各种 GIT 供应商的使用情况 - 您希望如何对存储库进行排序/分组?
回答by Dennis
lowercase-with-hyphens
is the style I most often see on GitHub.*
lowercase-with-hyphens
是我在 GitHub 上最常看到的风格。*
lowercase_with_underscores
is 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.git
would be cloned into the myDir
directory.
这里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-hyphens
and name your packages in composer or npm identically to your package on GitHub.
因此,我建议 PHP 和 JSlowercase-with-hyphens
包在 composer 或 npm 中使用和命名你的包,与你在 GitHub 上的包相同。