0

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)?

Jak
  • 181
  • 1
  • 2
  • 6
  • Are you trying to use hardlinks or symlinks? Can you give an example of the commands you're using to do this as a code block? – bk2204 Jul 25 '20 at 00:53

1 Answers1

2

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.

torek
  • 448,244
  • 59
  • 642
  • 775