git Github 将存储库更改为错误的语言

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34713765/
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-09 03:50:31  来源:igfitidea点击:

Github changes repository to wrong language

gitgithubrepositorygithub-linguist

提问by Echizzle

I know this isn't a huge deal but I like my Github to be linguistically diversified. I wrote a project in Swift and when I commit it says it's in Objective C.

我知道这没什么大不了的,但我喜欢我的 Github 语言多样化。我用 Swift 写了一个项目,当我提交时,它说它是在 Objective C 中的。

I think it might be because the Parse frameworks are written in Objective C and it detects that, but is there any way to change the display language on the main repository page?

我认为这可能是因为 Parse 框架是用 Objective C 编写的,它会检测到这一点,但是有没有办法更改主存储库页面上的显示语言?

回答by EamonnM

I found the simplest thing was to create a file called .gitattributesin the root folder of my repository, and give it these contents:

我发现最简单的方法是.gitattributes在我的存储库的根文件夹中创建一个名为的文件,并为其提供以下内容:

* linguist-vendored
*.js linguist-vendored=false

This example tells github/linguist to ignore all files, then just look at .js files. My project https://github.com/aim12340/jQuery-Before-Readywas listed as HTML because the HTML example files were bigger than the JS files. This file fixes it for me and now it's listed as JavaScript

这个例子告诉 github/linguist 忽略所有文件,然后只看 .js 文件。我的项目https://github.com/aim12340/jQuery-Before-Ready被列为 HTML,因为 HTML 示例文件比 JS 文件大。这个文件为我修复了它,现在它被列为 JavaScript

回答by VonC

As mentioned in the GitHub help page

GitHub 帮助页面中所述

GitHub uses the open source Linguist libraryto determine file languages for syntax highlighting and repository statistics.
Some files are hard to identify, and sometimes projects contain more library and vendor files than their primary code.

GitHub 使用开源语言学家库来确定用于语法突出显示和存储库统计的文件语言。
有些文件很难识别,有时项目包含的库和供应商文件比它们的主要代码还多。

So you need to check with github/linguist#troubleshootingin order to fix this situation.

所以你需要检查github/linguist#troubleshooting以解决这种情况。

The percentages are calculated based on the bytes of code for each language as reported by the List Languages API.
If the bar is reporting a language that you don't expect:

  • Click on the name of the language in the stats bar to see a list of the files that are identified as that language.
  • If you see files that you didn't write, consider moving the files into one of the paths for vendored code, or use the manual overrides featureto ignore them.
  • If the files are being misclassified, search for open issuesto see if anyone else has already reported the issue. Any information you can add, especially links to public repositories, is helpful.
  • If there are no reported issues of this misclassification, open an issueand include a link to the repository or a sample of the code that is being misclassified.

百分比是根据List Languages API报告的每种语言的代码字节计算的。
如果栏报告了您不期望的语言:

  • 单击统计栏中的语言名称以查看标识为该语言的文件列表。
  • 如果您看到不是您编写的文件,请考虑将文件移动到vendored code路径之一,或使用手动覆盖功能忽略它们。
  • 如果文件被错误分类,请搜索未解决的问题以查看是否有其他人已经报告了该问题。您可以添加的任何信息,尤其是公共存储库的链接,都是有帮助的。
  • 如果没有报告此错误分类的问题,请打开一个问题并包含指向存储库的链接或错误分类的代码示例。


Update February 2017 (one year later):

2017 年 2 月更新(一年后):

The article "How to Change Repo Language in GitHub" from Monica Powell

Monica Powell的文章“如何更改 GitHub 中的 Repo 语言

Upon researching how to resolve GitHub misclassifying the language of your projects I found out the solution is as simple as telling GitHub which files to ignore.

While you still want to commit these files to GitHub and therefore can't use a .gitignoreyou can tell GitHub's linguist which files to ignore in a .gitattributesfile

在研究如何解决 GitHub 错误分类项目语言的问题后,我发现解决方案就像告诉 GitHub 忽略哪些文件一样简单。

虽然您仍想将这些文件提交到 GitHub,因此无法使用 a,但.gitignore您可以告诉 GitHub 的语言学家在文件中忽略哪些.gitattributes文件

static/* linguist-vendored

This one-line file told GitHub to ignore all of my files in my static/folder which is where CSS and other assets are stored for a Flask app

这个单行文件告诉 GitHub 忽略我文件static/夹中的所有文件,这是为 Flask 应用程序存储 CSS 和其他资产的地方

The "Using .gitattributes" sectiondoes illustrate how to mark wrong languages.
For instance:

“使用.gitattributes”部分确实说明了如何标记错误的语言。
例如:

Checking code you didn't write, such as JavaScript libraries, into your git repo is a common practice, but this often inflates your project's language stats and may even cause your project to be labeled as another language.
By default, Linguist treats all of the paths defined in vendor.ymlas vendored and therefore doesn't include them in the language statistics for a repository.

Use the linguist-vendored attribute to vendor or un-vendor paths.

将您未编写的代码(例如 JavaScript 库)检查到您的 git 存储库中是一种常见做法,但这通常会夸大您项目的语言统计信息,甚至可能导致您的项目被标记为另一种语言
默认情况下,Linguist 将 中定义的所有路径vendor.yml视为 vendored,因此不会将它们包含在存储库的语言统计信息中。

将 linguist-vendored 属性用于供应商或非供应商路径。

$ cat .gitattributes
special-vendored-path/* linguist-vendored
jquery.js linguist-vendored=false

回答by Bright

To make it simple, let me share my steps:

为了简单起见,让我分享我的步骤:

  1. Change directory to your project root folder;

  2. Create a file named .gitattributes using whaterver tools of your choice:

    touch .gitattributes

  3. Edit the file by follow the Linguist libraryinstructions to tell Github how to do, for example:

    vi .gitattributes

    Use linguist-vendored can let Github to "skip" detection for this folder and sub-folders:

    src/main/resources/static/* linguist-vendored

    Use the linguist-documentation attribute to mark or unmark paths as documentation:

    project-docs/* linguist-documentation

    OR mark an individual file containing documentation

    documented_code.rb linguist-documentation=true

    This is a bit weird but you can do also -- to tell Github to treat some files with a specific extension (e.g. *.rb) as Java:

    *.rb linguist-language=Java

  4. Git add, commit and then push it to Github, the label would be corrected almost immediately.

  1. 将目录更改为您的项目根文件夹;

  2. 使用您选择的任何工具创建一个名为 .gitattributes 的文件:

    触摸 .git 属性

  3. 按照语言学家库的说明编辑文件,告诉 Github 如何做,例如:

    vi .git 属性

    使用 linguist-vendored 可以让 Github 对这个文件夹和子文件夹“跳过”检测:

    src/main/resources/static/* linguist-vendored

    使用 linguist-documentation 属性将路径标记或取消标记为文档:

    project-docs/* linguist-documentation

    或标记包含文档的单个文件

    documented_code.rb linguist-documentation=true

    这有点奇怪,但您也可以这样做——告诉 Github 将某些具有特定扩展名(例如 *.rb)的文件视为 Java:

    *.rb linguist-language=Java

  4. Git 添加、提交然后将其推送到 Github,标签几乎会立即被更正。

回答by Sumit

Replace your .gitattributes with this, which reclassifies allfiles as Java.

用这个替换你的 .gitattributes,这会将所有文件重新分类为 Java。

 *.* linguist-language=Java

linguist

语言学家

回答by Saif Siddiqui

Create .gitattributes file in the root of your folder. Suppose you want the language to be Java, just copy-paste

在文件夹的根目录中创建 .gitattributes 文件。假设您希望语言是 Java,只需复制粘贴

*.java linguist-detectable=true *.js linguist-detectable=false *.html linguist-detectable=false *.xml linguist-detectable=false

*.java linguist-detectable=true *.js linguist-detectable=false *.html linguist-detectable=false *.xml linguist-detectable=false

in the .gitattributes file and push the file in the repo.Refresh your GitHub page to see the language change.

在 .gitattributes 文件中并将文件推送到 repo.Refresh 你的 GitHub 页面以查看语言更改。

Note: So ,for the desired language make it true and other's false.It should work fine

注意:因此,对于所需的语言,使其为真,其他为假。它应该可以正常工作

回答by Slava

If you want to change the language of the Laravel repository, then add the following line to your .gitattributesfile:

如果您想更改 Laravel 存储库的语言,请将以下行添加到您的.gitattributes文件中:

*.blade.php linguist-vendored

GitHub defines blade files as html, but *.html linguist-vendoreddoesn't work.

GitHub 将刀片文件定义为 html,但*.html linguist-vendored不起作用。

回答by Drakonoved

You may avoid unexpected languages detection (by extension, or by project subfolder etc) by using github linguist detectable option:in your .gitattributesfile:

您可以通过使用github linguist 可检测选项:在您的.gitattributes文件中避免意外的语言检测(通过扩展名或项目子文件夹等):

Only programming languages are included in the language statistics. Languages of a different type (as defined in languages.yml) are not "detectable" causing them not to be included in the language statistics.

Use the linguist-detectableattribute to mark or unmark paths as detectable:

语言统计中只包含编程语言。不同类型的语言(如 中所定义languages.yml)无法“检测到”,导致它们不包括在语言统计中。

使用该linguist-detectable属性将路径标记或取消标记为可检测:

*.kicad_pcb linguist-detectable=true
*.sch linguist-detectable=true
tools/export_bom.py linguist-detectable=false

回答by Ethan Halprin

I had a project that was started in Objective-C and changed to Swift completely (new project but in same repository dir). Github kept identifying it as Objective-C no matter what I have put in gitattributes. (all solutions above)

我有一个在 Objective-C 中启动并完全更改为 Swift 的项目(新项目,但在同一存储库目录中)。无论我在 gitattributes 中放入什么,Github 一直将其标识为 Objective-C。(以上所有解决方案)

So, if the jig is up, and you're sure all project is one language - you radically put:

因此,如果夹具已启动,并且您确定所有项目都是一种语言 - 您从根本上说:

enter image description here

在此处输入图片说明

Only that fixed the problem :)

只有这样才能解决问题:)

回答by Ramil Mammadov

In .gitattributes file just tell Linguist not determine file languages which you don't want.

在 .gitattributes 文件中,只需告诉 Linguist 不要确定您不想要的文件语言。

Example for ignoring Javascript files.

忽略 Javascript 文件的示例。

*.js linguist-vendored

回答by fafa

The solution which was provided by the expert EamonnM who answered this question above worked in my project, but there's two significant things.

由回答上述问题的专家 EamonnM 提供的解决方案在我的项目中有效,但有两件重要的事情。

  1. The language in the beginning of the second line of his code was the language you want instead of the language you dislike. Remember to distinguish it.

  2. It seems that you could not type any space before the *. (For example, I should type *.swift linguist-vendored=falsewhen I want to change my language into swift.)

  1. 他的代码第二行开头的语言是你想要的语言,而不是你不喜欢的语言。记住要区分它。

  2. 似乎您无法在*. (例如,*.swift linguist-vendored=false当我想将语言更改为 swift 时,我应该输入。)