Symbolic link is a file that contains a reference to another file in your filesystem. You can add symlink to your repository, but by doing it you are only adding reference to other file and not that other file.
You can achieve what you want by creating hard link instead of symbolic link. Hard link is association between name of the file and its content (and metadata) on file system level. By creating hard link to a file and adding it to your repository, you are adding that linked file. On POSIX-compliant operating systems (like all the linuxes) you can create hard link like this:
ln /root/my_file my_hard_link
For more info about different kind of links see this question and its answers.
UPDATE: Please note that git doesn't know anything about hard links. Adding hard link to git repo means that you are adding content of that linked file. Git doesn't know that the file you've just added is a hard link. Adding hard link to repo won't break it, but checking it out of the repo will create a new copy of that file, and won't recreate that hard link. By "checking it out" I don't mean only git checkout
command, but also operations like clone
ing a new copy of the repo, deleting hard link and using git reset
to recreate it, or pull
ing new version of this hard linked file from remote repo.
To recap - your two options are:
- Add symbolic link to the repo - this will add only information about the link, and not content of the linked file.
- Add hard link to the repo - this will add content of the linked file. Although it won't add information about the link, it also won't break the link until next time you check that hard linked file out from the repo.
pull
? How about discarding local changes andcheckout
from your repo? I'm not saying you're wrong, but posts like this makes me doubt. – Holocrine