Git - how to handle symlinks

前端 未结 3 1322
情深已故
情深已故 2021-01-30 10:02

What is the correct way to handle symlinks in git?

I have the following structure:

Vendors
  Module A
  Module B
  Module C
App
 Code
   Modules
     Cor         


        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-30 10:46

    Git can handle symlinks just fine as long as the operating system used by all developers supports them. Since you depend on having these symlinks present I will assume that your development environments all support symlinks.

    To decide if something should be included in your git repository or not (symlink or otherwise) consider the following:

    • Is it a file generated by some tool or other process in the repository? If so, it's best to ignore it and let each user generate the file, so that they will always have the latest version.
    • Is the file specific to a particular user's development environment, or one that is used in all environments? If it's a quirk of a particular user's environment, like a configuration to ignore Emacs backup files, it doesn't belong in the repo. If it's something all developers will need, and/or something that's needed to build the application for production, it should go in the repository.

    In your case it seems like the symlinks are not generated and they are needed in all environments, so putting them in the repository should be fine.

    However, when creating them be sure to create them as relative symlinks rather than absolute symlinks, so that they'll work regardless of where the repository is cloned. The easiest way to do this is to change directory into the Modules directory and create the symlink from there:

    cd App/Code/Modules
    ln -s "../../../Vendors/Module A" "Module A"
    

提交回复
热议问题