Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git and hard links

Considering that Git does not recognize symbolic links that point outside of the repository, is there any problem using hard links?

Could Git break them? Can you please point me to detailed information?

like image 385
Alfredo Palhares Avatar asked Sep 16 '10 17:09

Alfredo Palhares


People also ask

Does Git work with hard links?

Git will handle a hard link like a copy of the file, except that the contents of the linked files change at the same time. Git may see changes in both files if both the original file and the hard link are in the same repository.

Does Git work with symlinks?

Git can track symlinks as well as any other text files. After all, as the documentation says, a symbolic link is nothing but a file with special mode containing the path to the referenced file.

What is the point of hard links?

A hard link always points a filename to data on a storage device. A soft link always points a filename to another filename, which then points to information on a storage device.

Should I use hard link or soft link?

In the end, the difference between hard links and soft links is pretty simple. Hard links are more forgiving when you delete a file, soft links take up less data because it's just pointing the way. However, soft links don't store the actual data, they just store the location of the original file.


1 Answers

The 'tree' object, representing directories in Git, stores file name and (subset of) permissions. It doesn't store inode number (or other kind of file id). Therefore hard links cannot be represented in git, at least not without third party tools such as metastore or git-cache-meta (and I am not sure if it is possible even with those tools).

Git tries to not touch files that it doesn't need to update, but you have to take into account that git doesn't try to preserve hardlinks, so they can be broken by git.


About symbolic links pointing outside repository: git has no problems with them and should preserve contents of symbolic links... but utility of such links is dubious to me, as whether those symlinks would be broken or not depends on the filesystem layout outside git repository, and not under control of git.

like image 156
Jakub Narębski Avatar answered Sep 24 '22 13:09

Jakub Narębski