3

I needed to create symbolic links / references to file from one repository to another.

I found the solution git: symlink/reference to a file in an external repository, which worked for me partially. But problem with this solution is that although the link was created, it seems to be bound to the one commit of the file. After the file is updated, commited and pushed, I cannot see the changes reflected in the other repository.

Does anybody know the other way how to create the symbolic link to the file in another repository in git, that would work like symbolic link in linux?

JanFi86
  • 449
  • 10
  • 29
  • You should update the submodule and commit the update in the superproject. – phd Jan 08 '20 at 16:27
  • Just to be sure : what you need is, from repo `A`, keep something that tracks the changes to file `target` which is versioned in repo `B` ? not : from folder `A`, which is the clone of a repo, have a symllink to a file in folder `B`, which is the clone of another repo ? – LeGEC Jan 08 '20 at 22:36
  • @phd I tried commit and update both repos, didn't work for me. – JanFi86 Jan 09 '20 at 11:11
  • @LeGEC basicaly, I need the first, but I thought the way how to do it is the second – JanFi86 Jan 09 '20 at 11:11
  • @JanFi86 : can you describe your use case in more details ? what is the role of this shared file ? a source code file ? some log file ? ... – LeGEC Jan 09 '20 at 14:27
  • @LeGEC for various reasons we need two repos but some files from repo B should be part of repo A due to creating package for bladelogic and deployment – JanFi86 Jan 09 '20 at 15:18

2 Answers2

4

This really appears to be a misunderstanding around how submodules work rather than an issue with symlinks. I highly suggest that you give the Submodules chapter of Pro Git a read.

For the purposes of this explanation let's define a few terms:

  • A will be the repository containing the target of your symlink (the link itself).
  • B will be the repository containing the source of that symlink.
  • C will be the submodule in A referencing B.

So you did a git submodule add B from A creating C, then did something along the lines of ln -s B/file file so that you have a symlink in A called file pointing to file within C. Everything works.

The problem, as described, appears to be that you then update file in B and push that change, however in A the symlink still shows the original content of file. The problem is that the C is just a clone of B: Just like any other clone of a repository the contents on disk do not change when you change what they were cloned from (eg: if you clone a repo from github and then somebody updates that repo on github the files on your local machine aren't changed). The solution is to update C and A: Go into C, pull the changes you want from B, then go to A and commit the change to the submodule.

Some people do find this process quite heavy. If that's the case for you the other answer you linked to does lay out a number of other ways of doing what you wish via scripting (or you could even script the submodule update process if you want).

Guildencrantz
  • 1,875
  • 1
  • 16
  • 30
0

I faced a similar issue where i couldnt modify the symlink path. but i was able to modify the link path directly on azuredevops file editor while retaining the integrity of the symlink.

Avindu Hewa
  • 1,608
  • 1
  • 15
  • 23