I would like to create links to files within a git repo. When I make changes to separate branches, changes are not reflected in the linked file. Is there any way to make links within a git repo (without having to make links for each branch)?
1 Answers
When git checkout
needs to replace a work-tree file, it calls unlink
first, then open(O_CREAT)
. This means that if you make a hard link from some existing work-tree file to some path name that exists outside the work-tree, the hard link is broken whenever Git itself replaces the work-tree copy of the file.
There is no flag to avoid this behavior.
(Making hard links within the Git repository—from some existing work-tree file to some new work-tree file—behaves similarly, in that Git will consider these to be two different files. If you git add
the second name and commit, you have made two different names for the same content, but Git won't hard-link the two files together later.)
In general, if you make a symbolic link outside your work-tree (or even inside it!) to a file that may or may not exist in your work-tree, that will work fine: the symbolic link will continue to contain the name of the file that may or may not exist in your work-tree, regardless of which version of that file you check out (or don't check out) from any given commit.

- 448,244
- 59
- 642
- 775