如何自动更改推送到 GitHub 的 Matlab 文件的文件扩展名?
我开始使用 Github 来托管我的大部分代码,包括我的 Matlab 代码。事实证明,Github 语法根据扩展名而不是文件内容来突出显示代码。这对于 Matlab m 文件来说不太好。它们被识别为 Objective-C 文件,也是 .m,并且被错误地识别/突出显示。 Github 确实会突出显示具有 .matlab 扩展名的 Matlab m 文件,但这样做的问题是 Matlab 似乎拒绝运行不具有 .m 扩展名的文件。我一直无法想出解决方案,因为我希望我的 matlab 文件能够与 Github 和 Matlab 很好地配合。所以这里有几个问题:
有没有办法在推送到 Github 时将所有 .m 文件转换为 .matlab 扩展名?从 Github 获取或克隆时,还需要将 .matlab 文件转换为 .m 扩展名?
如果 1. 不可能,有没有办法让 Matlab 运行扩展名为 .matlab 的文件?
如果 1 或 2 的答案是肯定的,我希望获得一些如何做到这一点的提示或示例。
I've started using Github for hosting much of my code, including my Matlab code. It turns out that Github syntax highlights code based on its extension rather than the content of the file. This is not so great for Matlab m files. They get recognized as Objective-C files, also .m, and improperly identified/highlighted. Github does highlight Matlab m files if they have the .matlab extension, but the problem with this is that Matlab seems to refuse to run files that that don't have the .m extension. I haven't been able to come up with a solution, as I'd like my matlab files to play nicely with both Github and Matlab. So here are couple of questions:
Is there a way to have all .m files converted to .matlab extensions when pushed to Github? This would also need to convert .matlab files to .m extensions when fetching or cloning from Github?
If 1. isn't possible, is there a way to get Matlab to run files that have a .matlab extension?
If yes to either 1 or 2, I'd love some tips or examples of how to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 git hooks 来完成问题中的第 1 点。如果您查看
.git/hooks/
,您会发现一些可以使用的示例(不同文件的作用已在 此处)。基本上,您需要做的就是添加一个 post-receive 挂钩,将 github 上的文件从.m
重命名为.matlab
以及一个 post-fetch 或 post-pull 挂钩(可能在这里稍微捏造了我的术语)这会将它们重命名回.m
文件。另外,看看关于 git hooks 的一些相关问题:1,< a href="https://stackoverflow.com/questions/2992128/pre-push-git-hook">2,3、4 等等...
也就是说,我同意 Alex 的观点,即更改存储库之间的扩展名通常不是一个好主意,因为您最终可能会破坏可能使用您的脚本的其他人的代码。
You can use git hooks to do point 1 in your question. If you look in
.git/hooks/
, you'll find some examples that you can use (what the different files do are explained here). Basically all you need to do is add a post-receive hook that will rename the files from.m
to.matlab
on github and a post-fetch or post-pull hook (might be fudging my terminologies a little here) that will rename them back to.m
files.Also, take a look at some of the related questions on git hooks on SO: 1, 2, 3, 4, and many more...
That said, I agree with Alex that it's generally not a good idea to change the extension between repositories, as you can end up breaking code for others who might use your scripts.
检查 Github 是否会尊重您的属性文件。如果是这样,则为 *.m 设置模式并设置适当的属性以获得正确的查看样式。
属性文件也是 eol=LF 的 matlab LF 标准化的地方(即使在 Windows 上)git-crlf-conversion-for-m-matlab-files
Check to see if Github will respect your attributes file(s). If so then set up a pattern for *.m and set the approprtiate attributes to ge the right viewing style.
The attributes file is also a place for the matlab LF normalisation of eol=LF (even on Windows) git-crlf-conversion-for-m-matlab-files