Git - how to handle symbolic links

What is the correct way to handle symbolic links in git?

I have the following structure:

Vendors Module A Module B Module C App Code Modules Core Module 1 Core Module 2 Module A (symlinked to vendors) Module B (symlinked to vendors) Module C (symlinked to vendors) 

There is a main application directory that contains all the main application code. In addition, there is a directory of suppliers that contains modules that receive a symbolic link in the main directory of the application and therefore are integrated.

It is important to note that both the vendor directory and the main application directory are both versioned in the same repository.

Therefore, should I let git store symbolic links or find a way to ignore symbolic links?

+56
git
Mar 17 '13 at 19:52
source share
3 answers

Git can do great with symbolic links as long as they are supported by the operating system used by all developers. Since you are dependent on the presence of these symbolic links, I will assume that your development environment supports symbolic links.

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

  • Is this a file created by any tool or other process in the repository? If so, it is best to ignore it and allow each user to generate a file so that they always have the latest version.
  • Is the file specific to a specific development environment for the user or for an environment that is used in all environments? If this is a fad of a particular user environment, such as a configuration to ignore Emacs backup files, it does not belong to the repo. If you need something that all developers will need, and / or something that is needed to create an application for production, it should go into the repository.

In your case, it seems that symbolic links are not generated, and they are necessary in all environments, so their placement in the repository should be great.

However, when creating them, be sure to create them as relative symbolic links, not absolute symbolic links, so that they work no matter where the repository is cloned. The easiest way to do this is to change the directory to the modules directory and create a symbolic link there:

 cd App/Code/Modules ln -s "../../../Vendors/Module A" "Module A" 
+111
Mar 17 '13 at 20:01
source share
β€” -

Git stores a symbolic link, like any other file in its version control - except for a symbolic link, it will store information about the path to which it is attached, and the file type as a symbolic link, not a regular file.

If a symbolic link points to a directory, git does not store the contents in a symbolic directory.

Thus, for your case there should be no harm in storing symbolic links, versions under git.

Another thing you need to know about symbolic links is that git will only recreate symbolic links to the new clone, not the file or directory that it points to. There is a possibility that the symbolic path will be nonexistent (say, when using absolute paths).

+8
Mar 17 '13 at 19:59
source share

@Tuxdude I can’t agree with you at all with "... then you are doing something wrong." As an example, if you need to place a media folder on another drive on a web server or even in NFS, you will have to set it out of version control. Thus, the contents inside the folder with symbolic media will not be accessible through version control, as you explained. But this is a scenario where you should do it. And this is really a pain in b ... My scenario is even more complicated (I will not go into details), what I'm really looking for is to add subfolders of the symbolic folder to version control, but not its contents, but I need to have an option where I can ignore any changes to the type of subfolder itself in git. For example, the basic structure:

  • app / media / bla
  • application / media / blubb

I need these folders in git version, without its contents.

On a web server (same version control), these folders look like this (symbolic links):

  • app / media / bla => somewhere else
  • app / media / blubb => somewhere completely again

Dev should have in its local environment only the initial structure described in the first stage (without symbolic links). But the web server has symbolic links to different NFS systems.

If anyone has an idea how to solve this, I would really appreciate it, because I have not yet found a solution for this.

The only way I'm doing this right now is to create a constructor that creates the correct / different structure for local environments, and media servers and subfolders are currently completely ignored by gitignore. But it can be difficult or difficult to maintain.

+1
May 25 '16 at
source share



All Articles