Github changes repository to wrong language

2019-01-21 01:07发布

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.

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?

6条回答
够拽才男人
2楼-- · 2019-01-21 01:46

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 library instructions 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.

查看更多
劳资没心,怎么记你
3楼-- · 2019-01-21 01:49

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

* 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-Ready was 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

查看更多
冷血范
4楼-- · 2019-01-21 01:52

Create a file named .gitattributes to your project root folder. Adding {file_name} linguist-generated=true can do the trick. In my case,

mvnw.cmd linguist-generated=true
mvnw linguist-generated=true

worked for me.

查看更多
别忘想泡老子
5楼-- · 2019-01-21 01:58

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

  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=false when I want to change my language into swift.)

查看更多
老娘就宠你
6楼-- · 2019-01-21 01:59

As mentioned in the GitHub help page

GitHub uses the open source Linguist library to 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.

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

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 feature to ignore them.
  • If the files are being misclassified, search for open issues to 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 issue and include a link to the repository or a sample of the code that is being misclassified.

Update February 2017 (one year later):

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

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 .gitignore you can tell GitHub’s linguist which files to ignore in a .gitattributes file

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

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

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.yml as 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.

$ cat .gitattributes
special-vendored-path/* linguist-vendored
jquery.js linguist-vendored=false
查看更多
在下西门庆
7楼-- · 2019-01-21 02:07

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)

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 :)

查看更多
登录 后发表回答