I recently added and committed a symbolic link to a text file (in an external directory) to a git repository. I expected this would commit the innards to the text file. However, when I cloned the repository to a second machine, the symbolic link was indeed still a symbolic link. It was now pointing at an unrelated text file (of the same name) on the second machine. My question is, why and how did git behave in this way?
Why is it possible to commit the actual link itself and when might this be useful?
Thank you!
In a nutshell, git add files for what they are (file, symlink, directory). This is usually fine if the symlink target is also in the source control, or at least in a known location.
If that conflicts with what you want to do, I'd first consider why you'd want the file be a symlink, and still be in version control in the first place. Chances are, you'll probably discover that you don't.
There is number of discussions about this here already, including some that explain why this is so, and how to work around it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With