开发者

Can git store the mime-type of a file, like SVN does, for browsing html?

I've just pushed my first repo to github but when I browse my html it is served as txt. Is this something that I can set similar to svn's props? Or is this simply a github inadequacy?

I can't seem to find anything on git, github or here tha开发者_StackOverflowt helps.


First, Subversion supports (versioned) properties (simple key=value pairs) on files, directories and revisions. This includes svn:mime-type property for a file. This approach (this feature) looks like remnants of original BerkeleyDB storage engine, and reminds a bit "resource forks" on (older?) MacOS filesystems.

The closest equivalent of Subversion's file properties in Git would be gitattributes (per-path attributes). You could define mime-type gitattribute, but currently no Git tool (known to me) uses it. Note that in contrast to Subversion gitattributes are stored in an ordinary file: in-tree .gitattributes file (which can be versioned), and per repository user's .git/info/attributes file... which can be edited in ordinary editor, and not only using SCM commands.


Second, mime-types or mimetype-like property or attribute is not really necessary. Gitweb (and probably other git interfaces) use file with extension to mimetype mapping (/etc/mime.types by default), so that e.g. '*.html' files are served in 'raw' mode (i.e. 'blob_plain' action) are served with 'text/html' content-type, see e.g. http://repo.or.cz/w/git.git/blob_plain/html:/gitattributes.html

It's the lack in GitHub web interface that http://github.com/git/git/raw/html/gitattributes.html is served with 'text/plain' content-type...


Git, unlike SVN is not concerned with individual files, rather with commits so I believe you cannot set mime-type props on files. On the other hand, github is a "code hosting site", which manages your code repositories and is only concerned about showing code. The exception from this rule is README files, where you can sort-of specify different formats (like .markdown) and render them as semi-HTML and wiki pages.

If what you want is to host your HTML files (like in a webserver) then github is not the place to do it. Rather, you can keep your files under github's version control, but check out and serve them from a webserver like apache.


File extension to mime-type mapping is, at best, a broken workaround. Two examples among many. Prolog used the .pl extension long before Perl existed. Files with a .txt extension may contain e.g. Markdown text and there often are good reasons to not use a .md or similar extension.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜