简体   繁体   中英

Git automatically changing file extensions

I have a git repo with some fortran source code with the file extension .for on windows. This code is compiled and run by a 3rd party software that throws an error if the file extension is not .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. So when I clone the git repo to a linux system, I have to change the fortran source files to .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 ?

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.

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 )
  • you can set up hooks for checkouts and commits in .git directory which rename the files before/after commit on need. You can set up it so that you will have .for on the local repo, but .f in the remote.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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