简体   繁体   English

Git自动更改文件扩展名

[英]Git automatically changing file extensions

I have a git repo with some fortran source code with the file extension .for on windows. 我在Windows上有一个git repo,上面有一些fortran源代码,文件扩展名为.for This code is compiled and run by a 3rd party software that throws an error if the file extension is not .for . 此代码由第三方软件编译和运行,如果文件扩展名不是.for则会抛出错误。 A rather annoying feature of this 3rd party software is that, on linux, it requires a .f file extension for the same fortran source code files. 此第三方软件的一个相当烦人的功能是,在Linux上,对于相同的fortran源代码文件,它需要一个.f文件扩展名。 So when I clone the git repo to a linux system, I have to change the fortran source files to .f . 因此,当我将git repo复制到linux系统时,必须将fortran源文件更改为.f How can I configure git to do this automatically, so when I clone to linux, all fortran files have a .f file extension and on windows the same files are .for ? 我如何配置git自动执行此操作,所以当我克隆到linux时,所有的fortran文件都具有.f文件扩展名,而在Windows上,相同的文件是.for吗?

It is not really a git problem, so the obstacle you found is mainly because you want to use a hammer for the task of a screwdriver. 这实际上不是一个git问题,所以发现的障碍主要是因为您想使用锤子来起子。

In your place I would do one of the followings: 在您的位置,我将执行以下操作之一:

  • git can handle symbolic links are well, so you can construct a symlink on the the .for for every .f files (for example: for x in *.f;do ln -svf ${x%.f}.for $x;done ) git可以很好地处理符号链接,因此您可以在.for为每个.f文件构造一个符号链接(例如: for x in *.f;do ln -svf ${x%.f}.for $x;done
  • you can set up hooks for checkouts and commits in .git directory which rename the files before/after commit on need. 您可以在.git目录中设置签出和提交钩子,以根据需要在提交之前/之后重命名文件。 You can set up it so that you will have .for on the local repo, but .f in the remote. 您可以对其进行设置,以便在本地存储库中使用.for ,而在远程存储库中使用.f

The first is much simpler, but not really beautiful. 第一个要简单得多,但并不是很漂亮。 The second is very beautiful, but requires tricky scripting, and it would be unstable (some tiny problem with the hooking scripts could harm your source). 第二个非常漂亮,但是需要技巧性的脚本编写,并且脚本不稳定 (钩脚本的一些小问题可能会损害您的源代码)。 To me, the first is better. 对我来说,第一个更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM