0

Let's consider we have a file f somewhere on the disk: /path/to/f

Since f is not inside my git repository (and has to remain at it's original position) I would like to create a link in my git repository, so that I do not have to manually copy changes of f every time into the git repository.

In other words: I would like git to track the contents of f, although f is not located in the repository.

How can I achieve this behavior? Is it possible to force git tracking the contents of links created with ln?

daniel451
  • 10,626
  • 19
  • 67
  • 125

1 Answers1

1

If you do ln /path/to/f /path/to/your/repo/f, the contents are stored fine in the repository, as you create a hard linke, meaning a second name for the same file on disk. If you change one, you change both, but for programes the files appear to be separate files but they are essentially only two pointers to the same file.

Vampire
  • 35,631
  • 4
  • 76
  • 102
  • Thanks! Are there any downsides of hard links? Do I have to double check something? Or can I use this without any concerns? – daniel451 Dec 14 '16 at 15:02
  • Well, as long as a hard link is pointing to an inode, the file data is not deleted, so if you only delete one of the hard links, your free space does not change as the other one is still pointing to the file. Other than that I cannot think of a downside for you. – Vampire Dec 14 '16 at 15:04
  • 1
    You will have to be careful of editors or other programs that like to write to a temporary file, remove the original and then rename the temporary. That will essentially break the hard link. – twalberg Dec 14 '16 at 18:06